PHP Basic Tutorial PHP Array

Source: Internet
Author: User
This section for you to introduce PHP arrays, arrays in PHP programming is very important, with a lot of places, it is recommended that you take good control.

1. Array definition:

     

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

Example 1,

 
       '; The function count calculates the number of elements//traversal array for ($i =0; $i
 
       
';}? >

Example 2,

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

Result: logo= Beijing pwm=123123=abc

Note: 1,//********** Special instructions

 
       "Logo", 45, 70,); Without defining the following table for the array, PHP will automatically use the largest number as the first subscript, followed by the element subscript automatically added 1//access to the value of the array of the logo we can write this//$arr [5] = "yes"; The value of the element is replaced by the Echo $arr [5]. '
'; Echo $arr [7];//by bbs.it-home.org

2.//Use decimal as key,php system to automatically truncate fractional parts

 
       "PPP" =>234,12.7=> "World");p Rint_r ($a);

Result: Array ([ABC] = [PPP] = 234 [[+]] = world)

3. Use True to false null as keyword (subscript)

 
       '; echo $a [null]. '
'; $a [22.6]=133; Use decimals as the key,php system to automatically truncate the fractional part//use Print_r to output an array to display an array of cases print_r ($a); Echo '
';//use Var_dump to display the information of the array in more detail var_dump ($a);

Effect: Hahaa China Array ([1] = what [0] = hahaa [] = [China] = 133) Array (4) {[1]=> string (4) "What" [0]=> ; String (5) "Hahaa" [""]=> string (6) "China" [22]=> Int (133)}

4, the PHP array can dynamically grow automatically

 
       

5. Several important functions in the array

  
        '; Number of elements of the statistic function echo is_array ($a). '
'; Determines whether an array is print_r ($a); Echo '
'; Var_dump ($a); Display array Information $b= "1 2 3 ' One ', '" Three ' "; Echo '
-------------------------';p rint_r (Explode ("", $b)) $b =array (); Echo count ($b);? >

Thank you for your attention to the PHP introductory tutorial, this series of basic PHP tutorial will help PHP novice friends, quickly master the language of PHP programming. The programmer's home will continue to introduce PHP-related tutorials For everyone, I wish you all the progress of learning!

  • 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.