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

How to modify array with php array_push()

青灯夜游
青灯夜游Original
2021-09-06 18:37:011689browse

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...)

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);
?>

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!

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