Mobile App Interface Programming Technology-learning to realize the PHP advanced array

Source: Internet
Author: User
Tags foreach array arrays interface key
Array creation, initializing

  
   '老大','2'=>'老三','1'=>'老二');
if( isset($arr3) ) {print_r($arr3);}
?>
Using the value of an array

  
   
Print data for a group
//直接通过index访问

  
   "我",'love'=>'爱','u'=>'你');

if(isset($arr))
{  
    foreach($arr as $key=>$value)
    {
      echo $value.'  ';  
    }
}
?>

Summarize

PHP arrays are divided into indexed array associative arrays

Associative array is an array of key values that are strings

For example, examples of foreach in the previous example.


  
   "我",
    'love'=>'爱',
    'li'=>'莉'
    ); 
    if(isset($arr))
    {
        foreach($arr as $key=>$value)
        {
          print_r($value); 
          //echo $value;
        }
    }
?>
Associative array creation, initializing

  
   '苹果');
$arr = array();
$arr['apple'] = '苹果';
if( isset($arr) ) {print_r($arr);}
?>
Associative array references (using the name of the array variable followed by the brackets + keys to access the values in the array, the keys are enclosed in single or double quotes.) )

  
   "苹果",'banana'=>"香蕉",'pineapple'=>"菠萝"
);

$arr0 = $arr['apple'];

if( isset($arr0) ) {print_r($arr0);}

?>


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.