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!
Recommended: "PHP Video Tutorial"
5 ways to define arrays
<?php echo "<hr>"; //定义数组的多种方法 //方法一 $array=array('orange','apple','banana'); var_dump($array);//打印数组array //方法二 $array[]='orange'; $array[]='apple'; var_dump($array);//打印数组array //方法三 $array=[];//这种不常见,但我觉得很简洁,类似于$array=array(); var_dump($array);//打印数组array //定义索引数组 //方法四 $array=array( 'orange'=>12, 'apple' =>18, ); var_dump($array);//打印数组array //方法五 $array['apple']=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!