Home  >  Article  >  Backend Development  >  Parsing the array_push() function in PHP

Parsing the array_push() function in PHP

autoload
autoloadOriginal
2021-05-06 10:40:382259browse

<img src="https://img.php.cn/upload/image/295/487/834/1620268826339661.jpg" title="1620268826339661.jpg" alt="Parsing the array_push() function in PHP">

phpWe often need to operate on arrays. Sometimes we may need to add units into the array,phpThe array_push() function is built into it, which can push one or more units to the end of the array (on the stack). This article will take you to take a look at it, and first understand the syntax.

array_push   ( array $array   , mixed $value1  , mixed $... = ?  )
  • $array: Input array.

  • $value1,...: To push the end value of array.

  • Return value: Returns the number of elements in the array after processing.

Code example:

<?php
$arr=array("a"=>"A张三","c"=>"b李四","b"=>"a王五");
$num=array_push($arr,"陆六","金七");
echo $num,"<br>";
print_r($arr);
?>
输出:5
     Array ( [a] => A张三 [c] => b李四 [b] => a王五 [0] => 陆六 [1] => 金七 )

Recommendation: 2021 PHP Interview Questions Summary (Collection) 》《php video tutorial

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