I have a PHP array similar to this:
0 => \"red\",
1 => \"green\",
2 => \"blue\",
3 => \"yellow\"
I want to move yellow to index
You want to move one of the elements to the beginning. Let's say
$old = array(
'key1' =>'value1',
'key2' =>'value2',
'key3' =>'value3',
'key4' =>'value4');
And you want to move key3 to the beginnig.
$new = array();
$new['key3'] = $old['key3']; // This is the first item of array $new
foreach($old as $key => $value) // This will continue adding $old values but key3
{
if($key != 'key3')$new[$key]=$value;
}