Home > Backend Development > PHP Problem > How to modify array with php array_push()

How to modify array with php array_push()

青灯夜游
Release: 2023-03-12 11:34:01
Original
1719 people have browsed it

In PHP, the array_push() function modifies the array by inserting one or more elements at the end of the array, and then returns the length of the array after inserting the new elements; use the syntax "array_push(array,value1,value2 ...)".

How to modify array with php array_push()

The operating environment of this tutorial: windows7 system, PHP7.1 version, DELL G3 computer

php array_push() function-- Modify the array by inserting elements at the end of the array

array_push() function adds one or more elements (push) to the end of the array of the first parameter, and then returns the Array length.

Grammar format:

array_push(array,value1,value2...)
Copy after login

Parameter description:

  • array Required, indicating an array;

  • value1, value2, ... represent the elements (values) that need to be inserted.

array_push() treats array as a stack and pushes the passed elements into the end of array. The length of array will increase according to the number of elements pushed onto the stack.

Example:

<?php
$arr=array(10,12,20);
array_push($arr,8,"9",3.14);
var_dump($arr);
?>
Copy after login

Output result:

How to modify array with php array_push()

Recommended learning: "PHP Video Tutorial"

The above is the detailed content of How to modify array with php array_push(). 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