PHP’s arrays are much more powerful than arrays in other languages. Let’s take a look at the basic concepts of arrays and how they are defined:
<?php /** * 数组 * 直接赋值声明数组,如下: * $arr = array("one"=>"111111","two"=>"222222"); * 其中,one、two是key(键名),111111、222222是value(值、也叫键值) */ echo "---------- 索引数组 : 下标是整数 ----------<br>"; $arr[0] = 1; $arr[1] = 2; $arr[2] = 3; print_r($arr); // 打印结果:Array ( [0] => 1 [1] => 2 [2] => 3 ) echo "<br>"; echo "---------- 关联数组 : 下标是字符串 ----------<br>"; $arr1['one'] = 1; $arr1['two'] = 2; $arr1['three'] = 3; print_r($arr1); // 打印结果:Array ( [one] => 1 [two] => 2 [three] => 3 ) echo "<br>"; echo "---------- 数组 Demo ----------<br>"; $arr2 = $arr + $arr1; print_r($arr2); echo "<br>"; echo "---------- 数组 Demo 2 ----------<br>"; $arr3[] = 1; $arr3[] = 2; $arr3[] = 3; $arr3[] = 4; print_r($arr3); echo "<br>"; /** * <pre class="brush:php;toolbar:false">标签 函数的结果格式化输出,即,按原型打印。阅读起来就比较方便。 * echo '<pre class="brush:php;toolbar:false">'; * print_r($arr); * echo ''; */ echo "---------- 数组 Demo 3 ----------
'; print_r($arr4); echo ''; /* 打印结果: Array ( [0] => 0 [1] => 1 [2] => 4 [3] => 9 [4] => 16 [5] => 25 [6] => 36 [7] => 49 [8] => 64 [9] => 81 ) */ echo "---------- 数组 Demo 4 ----------
'; print_r($arr5); echo ''; /* 打印结果: Array ( [0] => 0 [1] => 1 [2] => 4 [3] => 9 [刘德华] => 欧巴 [4] => 16 [5] => 25 [6] => 36 [-100] => 6666 [7] => 49 [8] => 64 [9] => 81 ) */ /** * 以下是几种定义数组的方式: */ echo "---------- 数组 Demo 5 ----------
The above is the content of Android programmers learning PHP development (19) - Basic concepts and definition methods of arrays (1) - PhpStorm. For more related content, please Follow the PHP Chinese website (m.sbmmt.com)!