PHP array_unshift()


array_unshift(array, value, ...) function adds elements to the beginning position of an array.

<?PHP
	$a = array(1,2,3);
	array_unshift($a,0);
	print_r($a);
	//Array ( [0] => 0 [1] => 1 [2] => 2 [3] => 3 ) 
	$a = array(1,2,3);
	array_unshift($a,0,9);
	print_r($a);
	//Array ( [0] => 0 [1] => 9 [2] => 1 [3] => 2 [4] => 3 ) 
	$a = array(1,2,3);
	array_unshift($a,0,array(9,10,11));
	print_r($a);
    //Array ( [0] => 0 [1] => Array ( [0] => 9 [1] => 10 [2] => 11 ) [2] => 1 [3] => 2 [4] => 3 ) 	
?>

Adds elements to the beginning of an associative array using array_merge() function.
<?PHP
	$a = array("John"=>"Male","Mary"=>"Female");
	$a=array_merge(array("George"=>"Male"),$a);
	print_r($a);
	//Array ( [George] => Male [John] => Male [Mary] => Female ) 
?>

array_shift(array) function delete an element at the beginning of an array.
<?PHP
	$a = array(1,2,3);
	array_shift($a);
	print_r($a);
    //Array ( [0] => 2 [1] => 3 ) 
?>

array_shift(array) can also delete an element at the beginning of an associative array.
<?PHP
	$a = array("George"=>"Male","John"=>"Male","Mary"=>"Female");
	array_shift($a);
	print_r($a);
	//Array ( [John] => Male [Mary] => Female ) 
?>