- 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);}?>
//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 . ; }}?>
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