Home  >  Article  >  Backend Development  >  array_push php array_push array function: push one or more cells to the end of the array (push)

array_push php array_push array function: push one or more cells to the end of the array (push)

WBOY
WBOYOriginal
2016-07-29 08:46:041209browse

Copy code The code is as follows:


/*Function array_push(): Push one or more units to the end of the array (push)
* 1. Syntax: int array_push (array &array, mixed var [, mixed ...] )
* 2. Description: Treat array as a stack and push the passed variable into the end of array. The length of array will increase according to the number of variables pushed onto the stack.
* 3. Notes:
* 3.1. This function returns the total number of new elements in the array
* 3.2. If var is an array, the array is pushed into the array stack as an array variable, which is the length of the original array It is to add a unit
*/
echo "****************************************** *******************************
";
$arr11=array('score 1'=> 65,'Grade 2'=>25,'Grade 3'=>87,'Grade 4'=>85,'Grade 5'=>45,'Grade 6'=>66);
$ arr22=array(a,b,c,d,e);
echo "Information of array arr11:";
echo "

"; 
print_r($arr11);
echo "
" ;
echo "Information of array arr22:";
echo "
"; 
print_r($arr22);
echo "
";
echo "The original number of elements of array arr1 is: ".count($arr11)."
";
$num1=array_push($arr11,12,55,66,100);
echo "After pushing onto the stack, the total number of elements in the array is:" .$num1."! The elements of the array at this time are:
";
echo "
"; 
print_r($arr11);
echo "
";
$ num2=array_push($arr11,$arr22);
echo "After array arr22 is pushed onto array arr11:";
echo "After being pushed onto the stack, the total number of elements in the array is: ".$num2."! At this time The elements of the array are:
";
echo "
"; 
print_r($arr11);
echo "
";
?>


Operation results As follows:

 php array_push数组函数:将一个或多个单元压入数组的末尾(入栈)

 php array_push数组函数:将一个或多个单元压入数组的末尾(入栈)

The above introduces the array_push php array_push array function: pushing one or more units to the end of the array (push), including the content of array_push. I hope it will be helpful to friends who are interested in PHP tutorials.

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