How to use array_shift function in php

藏色散人
Release: 2023-04-06 19:44:02
Original
2904 people have browsed it

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)
Copy after login

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); //打印处理后的数组
?>
Copy after login

Output:

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

php array_shift() function usage example 2

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

Output:

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

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!