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/** * No initial value created, given 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 * /  //Use double quotation marks, or single quotes, 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 through index access   $arr  = array  ( ' Zhang San ' ,  ' John Doe ' ,  ' King II ' ); for  ( $i  = 0 ;  $i  < 3 ;  $i  + +) {echo  $ Arr  [ $i ]. ; }?>    
//accesses the values in the array through a foreach Loop  <?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

For example, an example of foreach in the previous example.

<?php   $arr  = array  ( ' wo '  =>< Span class= "hljs-string" > "I" ,  ' love '  => ' AI '     ,  => ' Liz ' ); 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);}?>
    • An associative array reference that accesses the values in the array with the name of the array variable followed by the brackets + key, surrounded by single or double quotation marks. )
<?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.