PHP Array Usage

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.