* An array is an ordered collection of key names and values
* 1. Category:
* [Key name]
* 1.1 Index array [default]: The key name is an integer [it will be automatically converted if not]
* 1.2 Associative array: the key name is a string [can be converted into object properties]
* [Is the key value an array?]
* 1.1 One-dimensional array: The key value is a non-array type, the most commonly used
* 1.1 Multi-dimensional array: The key value is still an array, the most commonly used is a two-dimensional array, nesting is not recommended Too deep
* 2. Create:
* 2.1 Unified creation: $arr = [element1,element2,...];
* 2.2 Create one by one: $arr =[];$arr[]=element1;$arr[]=element2,...
* 3. Access: square brackets plus key name [key]
* 3.1 Overall: print_r($arr); var_dump($arr);
* 3.3 One by one: echo $array[key]: $array['name'];
* 4. Update:
* 4.1 Overall: It needs to be implemented through loop traversal: foreach($arr as $value){//...};
* 4.2 One by one: $arr[key] = new_value;
* 4.3 Clear or rebuild: $arr=[]; $arr = [1,2,3...]; Re-declaring it with the original name will overwrite the original array
* 5. Delete :
* 5.1 Overall: unset($arr);
* 5.2 Single deleted key name without rearrangement: unset($arr[key]);
* 5.3 Single deletion key name rearrangement [for index array]: array_splice($arr,$start,$count,[$newEle]);
* 5.4 Delete null value elements: array_filter($arr);
* 5.5 Delete specific elements: foreach if unset
//1.Create
$city = ['合肥','上海','杭州','南京']; //索引数组 $user = ['id'=>10,'name'=>'Peter','course'=>'php','grade'=>99]; //关联数组
//2.Access
print_r($user); //整体输出 echo '<hr>'; echo $user['name']; //查看单个元素 echo '<hr>';
//3.Update
$user['name']='朱老师'; //更新操作 echo $user['name']; //再次查看
//4.Delete
unset($city); //删除整个数组 echo '<pre class="brush:php;toolbar:false">'; print_r($city); //查看不存在的变量会报错,加@符可忽略Notice级错误 echo '<hr>'; unset($user['course']); //删除单个元素 echo '<pre class="brush:php;toolbar:false">'; print_r($user); //整体输出, $user['course']元素已经不存在了 echo '<hr>'; $city = ['合肥','上海','杭州','南京']; //索引数组 echo '<pre class="brush:php;toolbar:false">'; print_r($city); //原始索引数组 echo '<hr>'; echo '<pre class="brush:php;toolbar:false">'; //array_splice(arr,start,end,preserve):从数组特定位置取出指定数量的元素 //返回取出的数据,取出的数据从原始数组中删除掉 //从$city的第二个元素开始,取出2个并返回它们 print_r(array_splice($city,1,2)); echo '<pre class="brush:php;toolbar:false">'; //再次查看,会发现取出的元素,已经从原始数组中消失了 print_r($city); //整体输出