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

PHP Home Page

Manual Table of Contents
Up to Arrays
Quick Reference
English version of this pageGerman version of this pageItalian version of this pageFrench version of this pageHungarian version of this page
Arrays
* array
* array_count_values
* array_diff
* array_flip
* array_intersect
* 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 -- 配列の先頭から要素を一つ取り出す

説明

mixed array_shift (array array)

array_shift()は、array の最初の値を取り出して返します。配列 arrayは、 要素一つ分だけ短くなり、全ての要素は前にずれます。

例 1. array_shift()の例


$args = array ("-v", "-f");
$opt = array_shift ($args);
      
これにより、$argsには一つの要素"-f"が残り、$optは "-v"となります。

array_unshift(), array_push(), array_pop()も参照下さい。

注意: この関数は、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.