Home  >  Article  >  Backend Development  >  PHP array introductory tutorial - adding elements at the end of the array

PHP array introductory tutorial - adding elements at the end of the array

WBOY
WBOYOriginal
2016-07-25 08:57:571059browse
This article introduces the method of adding elements at the end of the array in PHP array operations. Friends in need can refer to it.

To add elements to the end of the array, use the php array operation function array_push.

array_push() function The return value is int type, which is the number of elements in the array after pushing the data. You can pass multiple variables as parameters to this function and push multiple variables into the array at the same time.

The form is: (array array,mixed variable [,mixed variable...])

Example, two more fruits are added to the $fruits array:

<?php
//在数组尾添加元素

$fruits = array("apple","banana");  
array_push($fruits,"orange","pear")  
//$fruits = array("apple","banana","orange","pear")  
?>


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