Adding an Element to the Beginning of an Array: int array_unshift(array $arr, mixed $val[, mixed $val2[, ...]]) : array_unshift « Data Structure « PHP






Adding an Element to the Beginning of an Array: int array_unshift(array $arr, mixed $val[, mixed $val2[, ...]])

 
<?php 
$prices = array(5.95, 10.75, 11.25); 
printf("<p>%s</p>\n", implode(', ', $prices)); 

array_unshift($prices, 10.85); 
printf("<p>%s</p>\n", implode(', ', $prices)); 


array_unshift($prices, 3.35, 17.95); 
printf("<p>%s</p>\n", implode(', ', $prices)); 
?>
  
  








Related examples in the same category

1.Adding an Element to the Beginning of an Array
2.array_unshift( ) function pushes value onto the start of the array
3.array_unshift() function shifts the array to the right.