Home >Backend Development >PHP Problem >How to add data to php array
How to add data to a php array: first create a PHP sample file; then define an array; and finally add new data to the array through the "array_push($a,44);" method.
The operating environment of this article: Windows 7 system, PHP version 7.1, DELL G3 computer
Two methods of adding new elements to an array in PHP
The code is as follows:
<?php $a = array(1); $a[] = 3; array_push($a,44); echo "<pre class="brush:php;toolbar:false">"; print_r($a);
Result:
Array ( [0] => 1 [1] => 3 [2] => 44 )
Recommended learning: "PHP Video Tutorial"
The above is the detailed content of How to add data to php array. For more information, please follow other related articles on the PHP Chinese website!