Home  >  Article  >  Backend Development  >  The difference between php arrays and objects

The difference between php arrays and objects

coldplay.xixi
coldplay.xixiOriginal
2020-07-23 14:50:343300browse

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

The difference between php arrays and objects is:

Array usage=>

Object usage->

<?php 
  $arr=[&#39;a&#39;=>123,&#39;b&#39;=>456]; //数组初始化 
  echo $arr[&#39;a&#39;]; //数组引用 
  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!

Statement:
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