Php array for basic PHP tutorials

Source: Internet
Author: User
Tags array definition php programming language
Php array for basic PHP tutorials
This section introduces php arrays. arrays are very important in php programming and are used in many places. we recommend that you master them well.

1. array definition:

     

[0]: represents the subscript of the array, or the keyword $ arr [0]: represents an element of the array $ arr [0] = represents the value of the array $ arr: array name

Example 1,

      '; // Function count calculates the number of elements // traverses the array for ($ I = 0; $ I
      ';}?>

Example 2,

      $ Val) {echo $ key. '='. $ val .'
';}

Result: logo = Beijing pwm = 123123 = abc

Note: 1. // *********** special instructions

      "Logo",); // if the following table is not defined for the array, PHP will automatically use the largest number above as the first subscript, the following element subscript automatically adds 1 // The value of accessing the logo array. we can write this // $ arr [5] = "yes "; the element value echo $ arr [5] is replaced.'
'; Echo $ arr [7]; // by bbs.it-home.org

2. // use decimals as the key. the PHP system automatically truncates the fractional part.

      12,'ppp'=>234,12.7=>"world");print_r($a);

Result: Array ([abc] => 12 [ppp] => 234 [12] => world)

3. use true false null as the keyword (subscript)

      '; Echo $ a [null].'
'; $ A [22.6] = 133; // use a decimal number as the key, PHP automatically truncates the fractional part. // outputs the array using print_r to display the array. print_r ($ a); echo'
'; // Use var_dump to display the array information in more detail var_dump ($ );

Result: hahaa Chinese Array ([1] => what [0] => hahaa [] => China [22] => 133) array (4) {[1] => string (4) "what" [0] => string (5) "hahahaa" [""] => string (6) "China" [22] => int (133 )}

4. PHP array can automatically grow

      

5. several important functions in the array

       '; // Count the number of elements in the function echo is_array ($ ).'
'; // Determine whether it is an array print_r ($ a); echo'
'; Var_dump ($ a); // Display array information $ B = "1 2 3 'one' two' 'Three'"; echo'
------------------------- '; Print_r (explode ("", $ B); $ B = array (); echo count ($ B);?>

Thanks for your attention to the php getting started tutorial. this series of basic php tutorials will help new php beginners to quickly master the php programming language. The programmer's home will continue to provide php tutorials for you and wish you a better learning experience!

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.