5 ways to define arrays in PHP

藏色散人
Release: 2023-04-09 17:34:01
forward
5813 people have browsed it

Below, the PHP tutorial column will introduce you to 5 ways to define arrays in PHP. I hope it will be helpful to friends in need!

5 ways to define arrays in PHP

Recommended: "PHP Video Tutorial"

5 ways to define arrays

<?php
echo "<hr>";
//定义数组的多种方法
//方法一
$array=array(&#39;orange&#39;,&#39;apple&#39;,&#39;banana&#39;);
var_dump($array);//打印数组array
//方法二
$array[]=&#39;orange&#39;;
$array[]=&#39;apple&#39;;
var_dump($array);//打印数组array
//方法三
$array=[];//这种不常见,但我觉得很简洁,类似于$array=array();
var_dump($array);//打印数组array
//定义索引数组
//方法四
$array=array(
  &#39;orange&#39;=>12,
  &#39;apple&#39; =>18,
);
var_dump($array);//打印数组array
//方法五
$array[&#39;apple&#39;]=18;
var_dump($array);//打印数组array
Copy after login

The above is the detailed content of 5 ways to define arrays in PHP. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
php
source:cnblogs.com
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