I have an array
$test = array('one', 'two', 'three', 'four', 'five');
I unset two and four (because I really really dislike even numbers)
unset($test[array_search('two', $test)]);
unset($test[array_search('four', $test)]);
And am left with an array
$test = array(
[0] => 'one',
[2] => 'three',
[4] => 'five'
);
Now I need to loop through that array and obtain the value along with the correct key. I want to display
0 = one
2 = three
4 = five
What should I use to achieve that? I tried using standard
for($i=0; $i<count($test); $i++)
but that is not effective because it will loop and give me 0 1 2 instead of 0 2 4.
Any suggestions?
You can use a foreach loop for this
Read about foreach loop at at php.net manual