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