การใช้งานฟังก์ชัน array_shift เป็นการดึงเอาค่าแรกของ array ออกมาจาก array ในกรณีที่ index ของ array เป็นตัวเลข index ของค่าใน array ที่เหลือจะถูกรีเซตค่าให้เริ่มต้นที่ 0 ส่วน index ที่ไม่เป็นตัวเลขก็จะยังอยู่เหมือนเดิม
ตัวอย่างการใช้งานฟังก์ชัน array_shift ของ PHP
<?php
$imoohcom = array("www", "imooh", "com");
$www = array_shift($stack);
print_r($stack);
?>
ผลลัพธ์ที่ได้
Array
(
[0] => imooh
[1] => com
)
และตัวแปร $www จะมีค่า “www”
ตัวอย่าง array ที่มี index ไม่เป็นตัวเลข
<?php
$imoohcom = array("www"=>"www", "imooh"=>"imooh", "com"=>"com");
$www = array_shift($stack);
print_r($stack);
?>
ผลลัพธ์ที่ได้
Array
(
[imooh] => imooh
[com] => com
)