The difference between php arrays and objects

coldplay.xixi
Release: 2023-03-03 07:06:02
Original
3283 people have browsed it

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); //查看对象
?>
Copy after login

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!

Related labels:
source:php.cn
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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!