Home >Backend Development >PHP Tutorial >5 ways to define arrays in PHP

5 ways to define arrays in PHP

藏色散人
藏色散人forward
2021-01-07 15:47:255848browse

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

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!

Statement:
This article is reproduced at:cnblogs.com. If there is any infringement, please contact admin@php.cn delete