How to add data to php array

藏色散人
Release: 2023-03-10 16:16:01
Original
5025 people have browsed it

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);
Copy after login

Result:

Array
(
    [0] => 1
    [1] => 3
    [2] => 44
)
Copy after login

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!

Related labels:
php
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!