PHP arrays are divided into two types;
<? php class Foo { var $foo < span> var $bar < span> var $fruits = array (' strawberry ' = ' red ', ' banana ' = ' yellow ' function Foo () { $this ->foo = ' foo ' < span> $this ->bar = array (' Bar1 ', ' Bar2 ', ' Bar3 ' ); }}
1. Indexed arrays
Use $foobar[4] = "Admin" To add data to the array, using echo $foo Bar[4] to get the value of an indexed array, using count () to get the length of the array;
Such as
<? PHP $foo New Foo (); $foo->bar[4] = "Admin"; Echo $foo->bar[4]; Echo Count ($foobar);? >
Output Admin 4;
2. Associative arrays
Use $foo, fruits["Name"]="Admin", add data to an array, use the $foo-Fruits[ "Name"] to obtain the corresponding value;
Such as
<?PHP$foo=NewFoo (); $foo->fruits["Name"]= "Admin"; Echo $foo->fruits["Name"]; foreach($$foo->fruits as $x=$x _value) { Echo"Key=".$x. ", value=."$x _value; Echo"<br>"; }?>
PHP Array Usage