Home  >  Article  >  Backend Development  >  php array_push() function

php array_push() function

怪我咯
怪我咯Original
2017-06-08 09:35:3810108browse

The array_push() function in php adds one or more elements (to the stack) to the end of the array of the first parameter, and then returns the length of the new array. This article introduces the syntax of the php array_push() function and some small examples. Let’s take a look.

php array_push() function

#php array_push() function?

The array_push() function in php adds one or more elements (to the stack) to the end of the array of the first parameter, and then returns the length of the new array. (Push: stack (stack), also known as stack, is a linear list with limited operations. Its restriction is that only insertion and deletion operations are allowed at one end of the list. This end is called the top of the stack. Relatively speaking, The other end is called the bottom of the stack. Inserting a new element into a stack is also called pushing, pushing or pushing. It puts the new element on top of the top element of the stack to make it the new top element; from a stack Deleting elements is also called popping or popping off the stack. It deletes the top element of the stack and makes its adjacent elements become new top elements of the stack.) This article introduces the syntax of the php array_push() function and some small examples. , let’s take a look together.

Definition and usage

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

array_push ( array &$array , mixed $value1 [, mixed $... ] ) : int

This function is equivalent to calling $array[] = $value multiple times.

Detailed explanation of syntax parameters

ParametersDescription
arrayRequired. Specifies an array.
value1Required. Specifies the value to add.
value2 Optional. Specifies the value to add.

Example 1

Use the php array_push() function to insert "blue" and "yellow" at the end of the array. The code is as follows:

Code running results:

php array_push() function

Example 2

Use the php array_push() function to add characters Add elements to the array of string key names. The code is as follows:

"red","b"=>"green");
array_push($a,"blue","yellow");
print_r($a);
?>

Code running result:

php array_push() function

[Related article recommendations]

Detailed explanation of php array_shift() function: delete the first element in the array

Detailed explanation of array_push(), array_pop() and array_shift() function usage examples in php

The above is the detailed content of php array_push() function. 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