Home  >  Article  >  Backend Development  >  How to use array_shift function in php

How to use array_shift function in php

藏色散人
藏色散人Original
2019-05-24 14:31:322870browse

Usage of array_shift function in php: [array_shift(array)]. The array_shift function is used to delete the first element in the array and return the value of the deleted element. If the array is empty, the function returns NULL.

How to use array_shift function in php

php The array_shift function is used to delete the first element in the array and return the value of the deleted element. Its syntax is array_shift(array), and the parameter array is required. , indicating a specified array.

(Recommended tutorial: php video tutorial)

How to use the php array_shift function?

Function: Delete the first element in the array and return the value of the deleted element.

Syntax:

array_shift(array)

Parameters:

array Required. Specifies an array.

Description:

Returns the value of the element removed from the array, or NULL if the array is empty.

php array_shift() function usage example 1

<?php
$a=array(0=>"西门",1=>"灭绝",2=>"无忌");
echo array_shift($a); //输出被删除的 数组元素的值
echo "<br>";
print_r ($a); //打印处理后的数组
?>

Output:

西门
Array ( [0] => 灭绝 [1] => 无忌 )

php array_shift() function usage example 2

<?php
$a=array(0=>"欧阳克",1=>"无忌",2=>"Peter_zhu");
echo array_shift($a); //输出被删除的 数组元素的值
echo "<br>";
print_r ($a); //打印处理后的数组
?>

Output:

欧阳克
Array ( [0] => 无忌 [1] => Peter_zhu )

The above is the detailed content of How to use array_shift function in php. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn