Home  >  Article  >  Backend Development  >  How to add data to php array

How to add data to php array

藏色散人
藏色散人Original
2021-06-16 10:24:225078browse

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.

How to add data to php array

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!

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