Home >Backend Development >PHP Problem >What is the usage of array_push in php

What is the usage of array_push in php

王林
王林Original
2021-07-06 14:27:232127browse

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

Let’s give an example:

<!DOCTYPE html>
<html>
<body>

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

</body>
</html>

Let’s see the running effect:

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

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!

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