★ wanayoo — archive 1999 http://www.php.net/manual/de/function.array-shift.phpNouvelle recherche | Portail wanayoo

PHP Home Page

Manual Table of Contents
Up to Arrays
Quick Reference
English version of this pageJapanese version of this pageItalian version of this pageFrench version of this pageHungarian version of this page
Arrays
* array
* array_count_values
* array_flip
* array_keys
* array_merge
* array_merge_recursive
* array_multisort
* array_pad
* array_pop
* array_push
* array_rand
* array_reverse
* array_shift
* array_slice
* array_splice
* array_unshift
* array_values
* array_walk
* arsort
* asort
* compact
* count
* current
* each
* end
* extract
* in_array
* key
* krsort
* ksort
* list
* next
* pos
* prev
* range
* reset
* rsort
* shuffle
* sizeof
* sort
* uasort
* uksort
* usort
Manual: array_shift
View the source code for this pageSearch the site



Previous page
 array_reverse
 Updated
Sat, 12 Aug 2000
array_slice 
Next page


array_shift

(PHP4 )

array_shift -- Pop an element off the beginning of array

Description

mixed array_shift (array array)

array_shift() shifts the first value of the array off and returns it, shortening the array by one element and moving everything down.

Beispiel 1. array_shift() example


$args = array("-v", "-f");
$opt = array_shift($args);
      
This would result in $args having one element "-f" left, and $opt being "-v".

See also array_unshift(), array_push(), and array_pop().

Anmerkung: This function was added in PHP 4.0.


User Contributed Notes: array_shift


ernie@ernie.org
11-Mar-2000 12:37
I assume you mean php3.. I'd like to know how as well. Maybe something like:
<pre>
$value_from_beginning=$array[0];
for($i=0;$array[$i];$i++) {
$array[$i]=$array[$i+1];
}
unset( $array[$i] );
</pre>
hey, that seems to work! I just made that up on the spot 8)



raedward@vt.edu
13-Apr-2000 01:54
But I don't think this will shorten the array, there will simply be a null element at the end. Sizeof() would still return the original number of elements in the array, right? Is there a way in 3.0 to resize an array?


dmelomed@home.com
24-Jul-2000 10:49
Here's how according to bsilva@umesd.k12.or.us:

$temp = $arr["first_key"];
for (reset($arr), next($arr); $key=key($arr); next($arr)) {
$arr2[$key]=$arr[$key];




 About Notes


Previous page
 array_reverse
 Updated
Sat, 12 Aug 2000
array_slice 
Next page





Who's responsible for this?
Top of this page

Site
Hosting:



Located in
United States
Elements of this website are subject to copyright.
Questions about installing or using PHP should be directed to one of the mailing lists.
Only questions about the website should be directed to webmaster@php.net.