Mobile App Interface Programming technology-learning to implement PHP advanced arrays

Source: Internet
Author: User

    • Array creation, initialization
<?phpCreate an array variable, arr, and try to create an indexed array/** * Without the initial value of the creation. Give value after creation * Note: The subscript must be an integer */  $arr=Array();$arr[0] =' Boss ';$arr[1] =' Dick ';if(isset($arr) {Print_r ($arr);}/** * with initial value creation * /  //Can be double-cited, or single-quote, array is starting from 0$arr 2=Array("Boss",' Dick ');if(isset($arr 2) {Print_r ($arr 2);}//Left is key, right is key value$arr 3=Array(' 0 '=' Boss ',' 2 '=' Old three ',' 1 '=' Dick ');if(isset($arr 3) {Print_r ($arr 3);}?>
    • Using the value of an array
<?php//从数组变量$arr中,读取键为0的值$arr = array(‘老大‘,‘老二‘);//$arr0 = $arr[‘0‘];$arr0 = $arr[0];if( isset($arr0) ) {print_r($arr0);}?>
    • Print array of data
//directly via index access   $arr  = array  ( ' Zhang San ' ,  ' John Doe ' ,  ' King II ' ); for  ( $i  = 0 ;  $i  < 3 ;  $i  + +) {echo  $ Arr  [ $i ]. ; }?>    
//through the Foreach loop to access the values in the array  <?php   $arr  =  Array  ( ' i '  => "I" ,  ' love '  => ' ai ' ,  ' u '  =>); if  (isset  ( $arr )) {foreach  ( $arr   As   $key  => $value ) {echo   $value .      ; }}?>   
    • Summarize

      The PHP array is divided into indexed array associative arrays

An associative array is an array of key values that are strings

Example of a foreach example in the previous example.

<?

php$arr = array( ‘wo‘=>"我", ‘love‘=>‘爱‘, ‘li‘=>‘莉‘ ); if(isset($arr)) { foreach($arr as $key=>$value) { print_r($value); //echo $value; } }?>

    • Associative array creation, initialization
<?

php//$arr = array(‘apple‘=>‘苹果‘);$arrarray();$arr[‘apple‘‘苹果‘;ifisset($arr) ) {print_r($arr);}?>

    • Associate an array reference (use the name of the array variable followed by the Bracket + key to access the values in the array.) The key is enclosed in either a single or double argument.

      )

<?php$arrarray(‘apple‘=>"苹果",‘banana‘=>"香蕉",‘pineapple‘=>"菠萝");$arr0$arr[‘apple‘];ifisset($arr0) ) {print_r($arr0);}?

>

Mobile App Interface Programming technology-learning to implement PHP advanced arrays

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.