What is the usage of array_push in php

王林
Release: 2023-03-11 09:28:01
Original
2069 people have browsed it

The usage of array_push in php is [array_push(array, value1, value2...)]. The array_push function adds one or more elements to the end of an array and returns the length of the new array.

What is the usage of array_push in php

The operating environment of this article: windows10 system, php 7.3, thinkpad t480 computer.

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.

Even if there are string key names in the array, the elements you add are always numeric keys.

Usage:

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

Let’s give an example:

<!DOCTYPE html>
<html>
<body>

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

</body>
</html>
Copy after login

Let’s see the running effect:

Array ( [0] => red [1] => green [2] => blue [3] => yellow )
Copy after login

Related video tutorial sharing: php video tutorial

The above is the detailed content of What is the usage of array_push in php. 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