Question: I have a PHP array similar to this:

```
0 => "red",
1 => "green",
2 => "blue",
3 => "yellow"

```

I want to move yellow to index 0. How do I do this?

Edit: My question is how do I move any one of these elements to the beginning? How would I move green to index 0, or blue to index 0? This question is not exclusively about moving the last element to the beginning.

Answer: 
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;
}

```
You can do like this:

```
$array = array("red", "green", "blue", "yellow");
$last = array_pop($array);
array_unshift($array, $last);
print_r($array);

```

**Result:**

```
Array ( [0] => yellow [1] => red [2] => green [3] => blue ) 

```