The difference between php arrays and objects is: arrays use [=>], the code is [$arr=['a'=>123] echo $arr['a']], and objects use 【->】, the code is 【$obj=new A();echo $obj->a;】.
The difference between php arrays and objects is:
Array usage=>
Object usage->
<?php $arr=['a'=>123,'b'=>456]; //数组初始化 echo $arr['a']; //数组引用 print_r($arr); //查看数组 echo "<br><br>"; //换行 class A{ public $a=123; public $b=456; } $obj=new A(); echo $obj->a; //对象引用 print_r($obj); //查看对象 ?>
Related learning recommendations: PHP programming from entry to proficiency
The above is the detailed content of The difference between php arrays and objects. For more information, please follow other related articles on the PHP Chinese website!