PHP/Data Structure/array unshift
Содержание
Adding an Element to the Beginning of an Array
<?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));
?>
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));
?>
array_unshift( ) function pushes value onto the start of the array
int array_unshift ( array &arr, mixed var [, mixed ...] )
<?
$firstname = "Johnny";
$names = array("Timmy", "Bobby", "Sam", "Tammy", "Joe");
array_unshift($names, $firstname);
?>
array_unshift() function shifts the array to the right.
//Its syntax is: int array_unshift(array array, mixed var1 [, mixed var2. . .])
//You can append one or several values simultaneously.
<?
$languages = array ("French", "Italian");
array_unshift ($languages, "Russian", "Chinese");
print_r($languages);
?>