I'm trying to manipulate the sorting order of an array. I would like to get the matching fruit - in this case the apple - as the third index on the array.
$array_fruit[] = array('fruit' => 'apple', 'color' => 'red');
$array_fruit[] = array('fruit' => 'banana', 'color' => 'yellow');
$array_fruit[] = array('fruit' => 'kiwi', 'color' => 'green');
$array_fruit[] = array('fruit' => 'orange', 'color' => 'orange');
$array_fruit[] = array('fruit' => 'strawberry', 'color' => 'red');
$array_fruit[] = array('fruit' => 'lemon', 'color' => 'yellow');
$i = 0;
$array_inStock = array();
foreach($array_fruit as $fruit)
{
if($fruit['fruit'] == 'apple')
{
$array_inStock['3'] = array('fruit' => $fruit['fruit'], 'color' => $fruit['color']);
}
else
{
$array_inStock[$i] = array('fruit' => $fruit['fruit'], 'color' => $fruit['color']);
}
$i++;
}
asort($array_inStock);
print_r($array_inStock);
I don't understand what is going wrong here. Anybody an idea? Big regards.