Phparray_shift (): deletes the first element in the array.

Source: Internet
Author: User
What is the function of phparray_shift? In php, the array_shift () function is used to delete the first element in the array and return the value of the deleted element. This article describes in detail the usage and definition of the phparray_shift () function. if you are interested, you can take a look and hope to help you. What is the role of the php array_shift () function?

In php, the array_shift () function is used to delete the first element in the array and return the value of the deleted element. This article describes in detail the usage and definition of the php array_shift () function. if you are interested, you can take a look and hope to help you.

Definition and usage

The array_shift () function deletes the first element in the array and returns the value of the deleted element. If the array is empty, NULL is returned .. If the key name is a number, all elements will get a new key name, starting from 0 and increasing with 1 (refer to the sample code below), the text key value remains unchanged.

Syntax

array_shift(array)

The parameter array is a specified array and must be specified.

Example 1

Use the php array_shift () function to delete the first element in the $ stack array and return the deleted element. the code is as follows:

 

Code running output result:

The code above deletes the first element in the $ stack array and assigns the element orange to $ fruit.

Example 2

Use the php array_shift () function to delete an array with a number key name. The code is as follows:

 "red",1=>"green",2=>"blue");echo array_shift($a);print_r ($a);?>

Code running output result:

We can see that the key name of the original element "green" is "1", but after the array_shift () function is used, all the key names start from 0.

[Recommended related articles]

Definition and usage of php array function array_push ()

Detailed examples of array_push (), array_pop (), and array_shift () functions in php

The above is a detailed explanation of the php array_shift () function: delete the details of the first element in the array. For more information, see other related articles in the first PHP community!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.