Forum Moderators: coopster
Now lets say I have a loop that prints out what is in the array.
I want to be able to remove blue green and yellow, but effectively shift down everything else in the array (in this case orange and grey) so that orange is now positioned relative to where blue was and grey is where green was. By this I mean x[1] = "blue"
and x[2] now equals "grey". How can I do this?
<?php
function my_colors($str){
if(in_array($str, array("blue", "green", "yellow"))) return false; else return true;
}$output_array = array_merge(array(), array_filter($array, "my_colors"));
?>
This should work! If not, then coopster may have a word about it:)
Best regards
Michal Cibor
array_shift() [php.net] does exactly what you want. You will just have to do some comparison during your loop to determine whether or not you want to shift the element off the array or not. That's where the in_array() [php.net] will come in handy.
The fellas have thrown out a few options here so you'll have to read up on the different functions and see what is going to work best for you.