1. Array (array), an array can store multiple data and can be of any type.
In fact, an array is equivalent to an ordered chart that maps values to keys.
<?php /* array( key1 => value1, key2 => value2, ... ) The key can be an integer or character type, and the value can be any type*/ $arr = array("foo" => "bar", 12 => true); print_r($arr); // View the entire contents of the value echo $arr["foo"]; // Access a single data through array subscript echo $arr[12]; // Access a single data through array subscript
2. Object. Object is a composite data type that is more advanced than arrays.
Object variables consist of a set of methods and a set of property values. The method represents the function of the object, and the properties represent the state of the object.
<?php class Person{ // Define a class var $name; // Define a member attribute function in the class say(){ // Define a member method echo "Doing foo."; } } $p = new Person; // Use the new statement to instantiate an object of class Person and place it in the variable $p $p->name = "Tom"; // Access the member properties in the object through the object $p $p->say (); // Access member methods in the object through object $P
The above are the two compound types in php variables. I hope it will be helpful to everyone.