* 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); //整体输出

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Dreamweaver Mac version
Visual web development tools

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

Safe Exam Browser
Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment

SublimeText3 English version
Recommended: Win version, supports code prompts!