Detailed explanation of php array_unshift() function (example)

王林
Release: 2023-04-09 13:56:02
Original
3255 people have browsed it

Detailed explanation of php array_unshift() function (example)

array_unshift() function is used to insert new elements into the array and return the number of elements in the new array. The values of the new array will be inserted at the beginning of the array.

(Recommended tutorial:php graphic tutorial)

Tip: You can insert one or more values. Numeric key names will start at 0 and increase by 1. String key names will remain unchanged.

Function syntax:

array_unshift(array,value1,value2,value3...)
Copy after login

Parameter description:

  • array Required. Specifies an array.

  • #value1 Required. Specifies the value to be inserted.

  • #value2 Optional. Specifies the value to be inserted.

  • #value3 Optional. Specifies the value to be inserted.

(Learning video recommendation:php video tutorial)

Example:

"red","b"=>"green"); array_unshift($a,"blue"); print_r($a); ?>
Copy after login

Run result:

Array ( [0] => blue [a] => red [b] => green )
Copy after login

The above is the detailed content of Detailed explanation of php array_unshift() function (example). 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
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!