Home > Backend Development > PHP Tutorial > PHP array operation function study notes_PHP tutorial

PHP array operation function study notes_PHP tutorial

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-07-13 10:49:58
Original
748 people have browsed it

Arrays in PHP are an indispensable part of our application development. Now I will share with you some of my own operations on learning PHP arrays. I hope that students who need to know more can refer to them.

For Web programming, the most important thing is accessing, reading and writing data. There may be many storage methods, including strings, arrays, files, etc. Arrays can be said to be one of the more important methods in PHP data applications. There are many array functions in PHP. The following is a summary of what I learned so that I can learn from them in the future.
. Array definition
The definition of an array is defined using the array() method. You can define an empty array:

The code is as follows Copy code
 代码如下 复制代码

$number = array(1,3,5,7,9);
//定义空数组
$result = array();
$color =array("red","blue","green");
//自定义键值
$language = (1=>"English",3=>"Chinese",5=>"Franch");
//定义二维数组
$two = array(
"color"=>array("red","blue"), //用逗号结尾
"week"=>array("Monday","Friday") //最后一句没有标点
);
?>

$number = array(1,3,5,7,9); //Define empty array
$result = array();
$color =array("red","blue","green");
//Custom key value

$language = (1=>"English",3=>"Chinese",5=>"Franch");
 代码如下 复制代码

$number = "1,3,5,7,9";
$string = "I'm PHPer";
$array = array("And","You?");
$newArray = compact("number","string","array");
print_r ($newArray);
?>

//Define a two-dimensional array

$two = array(
"color"=>array("red","blue"), //End with comma

"week"=>array("Monday","Friday") //The last sentence has no punctuation

);
?>



2. Create array

compact()
compact() function - Converts one or more variables (containing arrays) to an array: array compact (mixed $varname [, mixed $... ]).

The code is as follows Copy code
 代码如下 复制代码

$number = array("1","3","5","7","9");
$array = array("I","Am","A","PHP","er");
$newArray = array_combine($number,$array);
print_r ($newArray);
?>

$number = "1,3,5,7,9"; <🎜> $string = "I'm PHPer"; <🎜> $array = array("And","You?"); <🎜> $newArray = compact("number","string","array"); <🎜> print_r ($newArray); <🎜> ?>
The compact() function is used to convert two or more variables into arrays, including array variables of course. The parameter is the name of the variable rather than the full name with $. The opposite function is extract(). As the name suggests, it converts the array into a single string, with the key value as its string name and the array value as the string value. Running results: Array ( [number] => 1,3,5,7,9 [string] => I'm PHPer [array] => Array ( [0] => And [1] => You? ) ) array_combine() array_combine()——Reorganize two arrays into one array, one as the key value and the other as the value: array array_combine (array $keys, array $values)
The code is as follows Copy code
$number = array("1","3","5","7","9"); <🎜> $array = array("I","Am","A","PHP","er"); <🎜> $newArray = array_combine($number,$array); <🎜> print_r ($newArray); <🎜> ?>

I won’t go into details about the array_combine function, everyone will understand it after reading it.
Running result:
Array ( [1] => I [3] => Am [5] => A [7] => PHP [9] => er )
range()
range() function - creates an array of a specified range:

The code is as follows Copy code
代码如下 复制代码
$array1 = range(0,100,10);//0为起始值,100为结束值,10为步进值(默认步进值为1).
print_r($array1);
echo"
";
$array2 = range("A","Z");
print_r($array2);
echo "
";
$array3 = range("z","a");
print_r($array3);
?>
$array1 = range(0,100,10);//0 is the starting value, 100 is the ending value, and 10 is the step value (the default step value is 1).

print_r($array1);
echo"
";

$array2 = range("A","Z");
 代码如下 复制代码
$array = range(1,10);
$fillarray = range("a","d");
$arrayFilled = array_fill(0,5,$fillarray);//这里的$fillarray可以是字符串,如"test".
echo "
"; <br>
print_r ($arrayFilled); <br>
echo "
";
$keys = array("string","2",9,"SDK","PK");
$array2 = array_fill_keys($keys,"testing");
echo "
"; <br>
print_r ($array2); <br>
echo "
";
?>
print_r($array2);

echo "
";
$array3 = range("z","a");
print_r($array3);
?>
array_fill()
array_fill() function - fill array function:

The code is as follows Copy code
$array = range(1,10);
$fillarray = range("a","d");
$arrayFilled = array_fill(0,5,$fillarray);//$fillarray here can be a string, such as "test". echo "
"; <p>
print_r ($arrayFilled); <br>
echo "
";
$keys = array("string","2",9,"SDK","PK");
$array2 = array_fill_keys($keys,"testing");
echo "
"; <br>
print_r ($array2); <br>
echo "
";

?>

Run result:
Array
(
[0] => Array
(
[0] => a
[1] => b

[2] => c

[3] => d
)

[1] => Array
(
[0] => a
[1] => b

[2] => c

[3] => d
)

[2] => Array
(
[0] => a
[1] => b

[2] => c

[3] => d
)

[3] => Array
(
[0] => a
[1] => b
[2] => c
[3] => d

)

[4] => Array
(
[0] => a
[1] => b
[2] => c

[3] => d
 代码如下 复制代码

$speed = array(50,120,180,240,380);
foreach($speed as $keys=>$values){
echo $keys."=>".$values."
";
}
?>

) ) Array ( [string] => testing [2] => testing [9] => testing [SDK] => testing [PK] => testing ) 3. Array traversal foreach traversal foreach (array_expression as $value){} foreach (array_expression as $key => $value){}
The code is as follows Copy code
$speed = array(50,120,180,240,380); <🎜> foreach($speed as $keys=>$values){ echo $keys."=>".$values."
"; } ?>

Run result:
0=>50
1=>120
2=>180
3=>240
4=>380
while loop traversal
While loop traversal is generally combined with the list function. The following is an example

The code is as follows Copy code
代码如下 复制代码
$staff = array(
array("姓名","性别","年龄"),
array("小张","男",24),
array("小王","女",25),
array("小李","男",23)
);
echo "";
while(list($keys,$value) = each($staff)){
list($name,$sex,$age) = $value;
echo "";
}
echo "
$name$sex$age
";
?>
$staff = array(

array("name","gender","age"),

array("Xiao Zhang","Male",24),
 代码如下 复制代码
$speed = range(0,220,20);
for($i =0;$i echo $speed[$i]." ";
}
?>
array("小王","女",25),

array("Xiao Li","Male",23)
);
echo "

";
while(list($keys,$value) = each($staff)){
list($name,$sex,$age) = $value;

echo "";
$name$sex$age
 代码如下 复制代码
$speed = range(0,220,20);
echo current($speed);//输出当前位置的值(在数组的开头位置)
$i = rand(1,11);
while($i--){
next($speed);//指针从当前位置向后移动一位
}
echo current($speed);//输出当前位置的值
echo "
";
echo prev($speed);//输出前一位置数组值
echo "
";
echo reset($speed);//重置数组的指针,将指针指向起始位置
echo "
";
echo end($speed);//输出最后位置的数组值
echo "
";
?>
}

echo "";
?>
for loop traversal

The code is as follows Copy code
$speed = range(0,220,20);
for($i =0;$i
 代码如下 复制代码
$speed = range(0,200,40);
echo "each实现指针下移
";
echo "0挡的速度是".current(each($speed))."
";
echo "1挡的速度是".current(each($speed))."
";
echo "2挡的速度是".current(each($speed))."
";
echo "3挡的速度是".current(each($speed))."
";
echo "4挡的速度是".current(each($speed))."
";
echo "5挡的速度是".current(each($speed))."
";
echo "使用each函数实现数组指针的移动,进行数组遍历
";
reset($speed);//这里是将数组指针指向数组首
while(list($key,$value)=each($speed)){
echo $key."=>".$value."
";
}
?>
} ?> Run result: 0 20 40 60 80 100 120 140 160 180 200 220 4. Array pointer operations Involved functions include reset, prev, end, next, current, and each. Example 1: next and prev
The code is as follows Copy code
"; echo prev($speed);//Output the previous position array value echo "
"; echo reset($speed);//Reset the pointer of the array and point the pointer to the starting position echo "
"; echo end($speed);//Output the array value of the last position echo "
"; ?>
Run result: 0220 200 0 220 Example 2: each function pointer operation
The code is as follows Copy code
"; echo "The speed of 0 gear is".current(each($speed))."
"; echo "The speed of 1st gear is".current(each($speed))."
"; echo "The speed of 2nd gear is".current(each($speed))."
"; echo "The speed of 3rd gear is".current(each($speed))."
"; echo "The speed of 4th gear is".current(each($speed))."
"; echo "The speed of 5th gear is".current(each($speed))."
"; echo "Use each function to move the array pointer and traverse the array
"; reset($speed);//This is to point the array pointer to the beginning of the array while(list($key,$value)=each($speed)){ echo $key."=>".$value."
"; } ?>

Run result:
Each implements pointer movement down
The speed of gear 0 is 0
The speed of 1st gear is 40
The speed in 2nd gear is 80
The speed in 3rd gear is 120
The speed in 4th gear is 160
The speed in 5th gear is 200
Use each function to move the array pointer and traverse the array
0=>0
1=>40
2=>80
3=>120
4=>160
5=>200
5. Array addition and deletion operations
Add array members
Example 1: $num[] = value is directly assigned and appended to the end of the array:
[code

The code is as follows Copy code
]
代码如下 复制代码
] $num = array(1=>80,2=>120,3=>160);
echo "使用表达式添加数组成员
";
$num[]=240;
print_r($num);
?>
$num = array(1=>80,2=>120,3=>160);

echo "Add array members using expressions
";
$num[]=240;
print_r($num);
?>

Run result:
 代码如下 复制代码

$num = array(1=>80,2=>120,3=>160);
$num = array_pad($num,4,200);
echo "使用array_pad函数向数组尾部添加成员
";
print_r($num);
echo "
array_pad 还可以填充数组首部
";
$num = array_pad($num,-8,40);
print_r($num);
?>

Add array members using expressions

Array ( [0] => 80 [1] => 120 [2] => 160 [3] => 240 )
Example 2: array_pad function, selective appending of the beginning and end of an array

The code is as follows Copy code

$num = array(1=>80,2=>120,3=>160);
$num = array_pad($num,4,200); echo "Use the array_pad function to add members to the end of the array
";
 代码如下 复制代码
$num = array(1=>80,2=>120,3=>160);
array_push($num,200,240,280);//可以自己追加,直接加在数组结尾
print_r($num);
?>
print_r($num);

echo "
array_pad can also fill the array header
";
$num = array_pad($num,-8,40);
print_r($num);

?>
 代码如下 复制代码

$num = array(1=>80,2=>120,3=>160);
array_unshift($num,0,40);//可以自己追加,直接加在数组结尾
print_r($num);
?>

Run result: Use the array_pad function to add members to the end of the array Array ( [0] => 80 [1] => 120 [2] => 160 [3] => 200 ) array_pad can also fill the array header Array ( [0] => 40 [1] => 40 [2] => 40 [3] => 40 [4] => 80 [5] => 120 [6] => 160 [7] => 200 ) Example 3: Add push operation (array_push):
The code is as follows Copy code
$num = array(1=>80,2=>120,3=>160); array_push($num,200,240,280);//You can append by yourself, directly at the end of the array print_r($num); ?>
Run result: Array ( [1] => 80 [2] => 120 [3] => 160 [4] => 200 [5] => 240 [6] => 280 ) Example 4: array_unshift() adds array members at the beginning
The code is as follows Copy code
$num = array(1=>80,2=>120,3=>160); array_unshift($num,0,40);//You can add it yourself, directly at the end of the array print_r($num); ?>

Run result:
Array ( [0] => 0 [1] => 40 [2] => 80 [3] => 120 [4] => 160 )
Note: After using the array_unshift() function, the key values ​​of the array will start from 0!
Delete array members
Example 1: The unset() command deletes array members or arrays:

The code is as follows Copy code
 代码如下 复制代码
$num = array_fill(0,5,rand(1,10));
print_r($num);
echo "
";
unset($num[4]);
print_r($num);
echo "
";
unset($num);
if(is_array){
echo "unset命令不能删除整个数组";
}else{
echo "unset命令可以删除数组";
}
?>
$num = array_fill(0,5,rand(1,10));

print_r($num);
echo "
";
unset($num[4]);

print_r($num);

echo "
";
unset($num);
if(is_array){

echo "unset command cannot delete the entire array";
 代码如下 复制代码
$a=array("red", "green", "blue", "yellow");
count ($a); //得到4
array_splice($a,1,1); //删除第二个元素
count ($a); //得到3
echo $a[2]; //得到yellow
echo $a[1]; //得到blue
?>
}else{

echo "unset command can delete arrays";

}
 代码如下 复制代码

$a=array("red", "green", "blue", "yellow","blue","green");
$result = array_unique($a);
print_r($result);
?>

?>

Running result: (Running error and description array are also deleted and no longer exist)
Array ( [0] => 9 [1] => 9 [2] => 9 [3] => 9 [4] => 9 )
Array ( [0] => 9 [1] => 9 [2] => 9 [3] => 9 )

 代码如下 复制代码
$array1 = array("r"=>"red",1,2,3,4);
$array2 = array("b"=>"blue",4=>5,6,7,8,9);
$array3 = array("r"=>"read",4=>10,2=>11);
$array4 = array(
array(4=>10),
array(7=>13)
);
$array5 = array(
array(4=>11),
array(6=>12)
);
$result = array_merge($array1,$array2,$array3,$array4,$array5);
echo "
"; <br>
print_r($result); <br>
echo "
";
$result = array_merge_recursive($array1,$array2,$array3,$array4,$array5);
echo "
"; <br>
print_r ($result); <br>
echo "
";
?>
Notice: Use of undefined constant is_array - assumed 'is_array' in H:wampwwwtestingeditorplustest.php on line 21 The unset command cannot delete the entire array Example 2: array_splice() function deletes array members
The code is as follows Copy code
$a=array("red", "green", "blue", "yellow"); <🎜> count ($a); //Get 4 <🎜> array_splice($a,1,1); //Delete the second element <🎜> count ($a); //Get 3 <🎜> echo $a[2]; //get yellow <🎜> echo $a[1]; //get blue <🎜> ?>
Example 3: array_unique deletes duplicate values ​​in the array:
The code is as follows Copy code
$a=array("red", "green", "blue", "yellow","blue","green"); <🎜> $result = array_unique($a); <🎜> print_r($result); <🎜> ?>
Run result: Array ( [0] => red [1] => green [2] => blue [3] => yellow ) Example 4: array_merge, array_merge_recursive merge arrays
The code is as follows Copy code
$array1 = array("r"=>"red",1,2,3,4); $array2 = array("b"=>"blue",4=>5,6,7,8,9); $array3 = array("r"=>"read",4=>10,2=>11); $array4 = array( array(4=>10), array(7=>13) ); $array5 = array( array(4=>11), array(6=>12) ); $result = array_merge($array1,$array2,$array3,$array4,$array5); echo "
"; 
print_r($result); 
echo "
"; $result = array_merge_recursive($array1,$array2,$array3,$array4,$array5); echo "
"; 
print_r ($result); 
echo "
"; ?>

运行结果:
Array
(
[r] => read
[0] => 1
[1] => 2
[2] => 3
[3] => 4
[b] => blue
[4] => 5
[5] => 6
[6] => 7
[7] => 8
[8] => 9
[9] => 10
[10] => 11
[11] => Array
(
[4] => 10
)

[12] => Array
(
[7] => 13
)

[13] => Array
(
[4] => 11
)

[14] => Array
(
[6] => 12
)

)
Array
(
[r] => Array
(
[0] => red
[1] => read
)

[0] => 1
[1] => 2
[2] => 3
[3] => 4
[b] => blue
[4] => 5
[5] => 6
[6] => 7
[7] => 8
[8] => 9
[9] => 10
[10] => 11
[11] => Array
(
[4] => 10
)

[12] => Array
(
[7] => 13
)

[13] => Array
(
[4] => 11
)

[14] => Array
(
[6] => 12
)

)

注:1. array_merge的键名是数字的将重新建立索引;遇到相同的字符串键名时,后面的将覆盖前面的。 2. array_merge_recursive函数的作用是将相同字符串的键名单元整合成一个数组。
6. 数组的键值和值操作
实例一:in_array()检测数组中是否有某个值存在

 代码如下 复制代码
 代码如下 复制代码

$array = range(0,9);
if(in_array(9,$array)){
echo "数组中存在";
}
?>

$array = range(0,9);
if(in_array(9,$array)){

echo "数组中存在";
代码如下 复制代码

$array = range(0,9);
$num = rand(0,8);
while($num--)
next($array);
$key = key($array);
echo $key;
?>

}

?>

运行结果:数组中存在
 代码如下 复制代码
$staff = array(
array("姓名","性别","年龄"),
array("小张","男",24),
array("小王","女",25),
array("小李","男",23)
);
echo "";
while(list($keys,$value) = each($staff)){
list($name,$sex,$age) = $value;
echo "";
}
echo "
$name$sex$age
";
?>
实例二:key()取得数组当前的键名:
 代码如下 复制代码
$array = range(0,9); <🎜> $num = rand(0,8); <🎜> while($num--) <🎜> next($array); <🎜> $key = key($array); <🎜> echo $key; <🎜> ?>
此实例结果为动态结果,范围(0-8),不做结果演示。 实例三:list()函数把数组中的值赋给指定变量: "; } echo "
 代码如下 复制代码
"; while(list($keys,$value) = each($staff)){ list($name,$sex,$age) = $value; echo "
$name$sex$age
"; ?>

实例四:array_flip()交换数组的键值和值:

 代码如下 复制代码
 代码如下 复制代码

$array = array("red","blue","yellow","Black");
print_r($array);
echo "
";
$array = array_flip($array);
print_r($array);
?>

$array = array("red","blue","yellow","Black");
print_r($array);
echo "
";

$array = array_flip($array);
 代码如下 复制代码

$array = array("red","blue","yellow","Black");
$result = array_keys($array);
print_r($result);
echo "
";
$result = array_values($array);
print_r($result);
?>

print_r($array);

?>


运行结果:
Array ( [0] => red [1] => blue [2] => yellow [3] => Black ) Array ( [red] => 0 [blue] => 1 [yellow] => 2 [Black] => 3 )
 代码如下 复制代码

$array = array("red","blue","yellow","Black");
$result = array_search("red",$array);
if(($result === NULL)){
echo "不存在数值red";
}else{
echo "存在数值 $result";
}
?>

 代码如下 复制代码

$array = array("red","blue","yellow","Black");
$result = array_keys($array);
print_r($result);

echo "
";
 代码如下 复制代码

$array = array("b","c","d","a");
sort($array);//从低到高排序
print_r($array);
echo "
";
rsort($array);//逆向排序
print_r($array);
?>

$result = array_values($array);

print_r($result);
?>


运行结果:
Array ( [0] => 0 [1] => 1 [2] => 2 [3] => 3 )
Array ( [0] => red [1] => blue [2] => yellow [3] => Black ) 实例六:array_search()搜索数值:
 代码如下 复制代码

$array = array("a","b","c","d");
shuffle($array);//从低到高排序
print_r($array);
?>

 代码如下 复制代码
$array = array("red","blue","yellow","Black"); <🎜> $result = array_search("red",$array); <🎜> if(($result === NULL)){ <🎜> echo "不存在数值red"; <🎜> }else{ <🎜> echo "存在数值 $result"; <🎜> } <🎜> ?>
结果:存在数值 0 函数array_search()返回的值可能为false或0或NULL,所以在判断时注意要用"===" 7. 数组的排序 实例一:sort()、rsort()/asort()、arsort()对数组排序:
 代码如下 复制代码
"; rsort($array);//逆向排序 print_r($array); ?>
结果: Array ( [0] => a [1] => b [2] => c [3] => d ) Array ( [0] => d [1] => c [2] => b [3] => a ) sort()、rsort()函数对数组进行从低到高的排序,返回结果为bool值; asort()、arsort()函数是保留键值的排序,排序后键值不重新索引。 实例二:将数组顺序打乱——shuffle()函数:
 代码如下 复制代码
$array = array("a","b","c","d"); <🎜> shuffle($array);//从低到高排序 <🎜> print_r($array); <🎜> ?>

The result is dynamic:
Array ( [0] => c [1] => a [2] => d [3] => b )
The result of shuffle is a bit random and different every time it is refreshed.
Example 3: array_reverse() array reverse:

The code is as follows Copy code
 代码如下 复制代码

$array = array("d","b","a","c");
$array = array_reverse($array);//从低到高排序
print_r($array);
?>

$array = array("d","b","a","c");
$array = array_reverse($array);//Sort from low to high
print_r($array);

?>
 代码如下 复制代码

$array = array("sort2","Sort5","sort1","sort4");
natsort($array);//从低到高排序
print_r($array);
echo "
";
natcasesort($array);
print_r($array);
?>

Run result:
Array ( [0] => c [1] => a [2] => b [3] => d )
Example 4: Natural sorting algorithm - natsort() and natcasesort();

The code is as follows Copy code

$array = array("sort2","Sort5","sort1","sort4");
代码如下 复制代码

$array = array(1=>"sort2",4=>"Sort5",2=>"sort1",3=>"sort4");
ksort($array);//从低到高排序
print_r($array);
?>

natsort($array);//Sort from low to high

print_r($array);
echo "
";
natcasesort($array);

print_r($array);

?>

Result:

Array ( [1] => Sort5 [2] => sort1 [0] => sort2 [3] => sort4 )
 代码如下 复制代码

array = array ('A', 'B', 'C' );
//使用int array_unshift(array $array,mixed variable[,mixed variable…])在数组头添加元素
array_unshift ( $array, 'E', 'F', 'G' );
var_dump ( $array );
 

$array = array ('A', 'B', 'C' );
//使用int array_push(array $array,mixed variable[,mixed variable…])在数组结尾添加元素
array_push ( $array, 'E', 'F', 'G' );
var_dump ( $array );
 

$array = array ('A', 'B', 'C' );
//使用mixed array_shift(array $array)在数组头删除元素
array_shift ( $array );
var_dump ( $array );
 

$array = array ('A', 'B', 'C' );
//使用mixed array_pop(array $array)在数组尾删除元素
array_pop ( $array );
var_dump ( $array );

Array ( [2] => sort1 [0] => sort2 [3] => sort4 [1] => Sort5 ) natsort() and natcasesort() perform natural sorting on arrays, which is the normal sorting algorithm using numbers. natcasesort ignores case. Example 5: Sort the array by key value ksort():
The code is as follows Copy code
$array = array(1=>"sort2",4=>"Sort5",2=>"sort1",3=>"sort4"); ksort($array);//Sort from low to high print_r($array); ?>
Result: Array ( [1] => sort2 [2] => sort1 [3] => sort4 [4] => Sort5 ) Note: The ksort() function re-indexes. 8. Other uses of arrays $
The code is as follows Copy code
array = array ('A', 'B', 'C' ); //Use int array_unshift(array $array,mixed variable[,mixed variable...]) to add elements to the head of the array array_unshift ( $array, 'E', 'F', 'G' ); var_dump ( $array ); $array = array ('A', 'B', 'C' ); //Use int array_push(array $array,mixed variable[,mixed variable...]) to add elements at the end of the array array_push ( $array, 'E', 'F', 'G' ); var_dump ( $array ); $array = array ('A', 'B', 'C' ); //Use mixed array_shift(array $array) to delete elements at the head of the array array_shift ( $array ); var_dump ( $array ); $array = array ('A', 'B', 'C' ); //Use mixed array_pop(array $array) to delete elements at the end of the array array_pop ( $array ); var_dump ( $array );

/*
* Search for a specific value in the array, return TRUE if found otherwise return FALSE
* boolean in_array(mixed needle,array haystack[,boolean strict])
* Find a specified key in the array, return TRUE if found, otherwise return FALSE
* boolean array_eky_exists(mixed key,array array)
* Search for a specific value in the array, return TRUE if found otherwise return FALSE
* boolean array_search(mixed needle,array haystack[,boolean strict])
* Get a new array composed of all keys of the array
* array array_keys(array array[,mixed search_value])
* Get a new array composed of all values ​​in the array
* array array_values(array array)
* Determine array size
* integer count(array array[,int mode])
* integer sizeof(array array[,int mode])
* Count the frequency of occurrence of array elements
* array array_count_values(array array)
* Remove duplicate values ​​from the array and return an array composed of unique values ​​
* array array_unique(array array)
* Reverse the order of array elements. If preserve_key is TRUE, the order of array key values ​​will remain unchanged
* array array_reverse(array array[,boolean preserve_key])
* Replace array keys and values ​​
* array array_flip(array array)
* Array order sorting, sort_flags parameter is optional, default behavior
* SORT_NUMBERIC, sort by numerical value, useful for sorting integers or floating point numbers
*SORT_REGULAR, sort by ASCII value
* SORT_STRING, sorted in the correct order known by people closest to you
* The key value order of the asort function remains unchanged
* void sort(array array[,int sort_flags])
* void asort(array array[,int sort_flags])
* Sort the array in reverse order, the sort_flags parameter is optional, and the default behavior is
* SORT_NUMBERIC, sort by numerical value, useful for sorting integers or floating point numbers
*SORT_REGULAR, sort by ASCII value
* SORT_STRING, sorted in the correct order known by people closest to you
* The key value order of the arsort function remains unchanged
* void rsort(array array[,int sort_flags])
* void arsort(array array[,int sort_flags])
* Natural sorting of arrays
* void natsort(array array)
* Case-insensitive natural sorting
* void natcasesort(array array)
* Sort array by key value
* boolean ksort(array array[,int sort_flags])
* Sort the array in reverse order by key value
* boolean krsort(array array[,int sort_flags])
* Sort according to user-defined order
* void usort(array array,callback function_name)
* Merge the arrays together to return a combined array. The back of array_merge covers the front, array_merge_recursive merges together
* array array_merge(array array1[array array2...])//More than one
* array array_merge_recursive(array array1,array array2[,array…])//More than two
* Keys and values ​​form a new array
* array array_combine(array key,array value)
* Return a part of the array, starting from offset and ending at offset+length
* array array_slice(array array, int offset [,int length])
* Delete all elements starting from offset and ending at offset+length, and return the deleted elements in the form of an array
* array array_splice(array, int offset [,int length[,array peplacement]])
* Find the intersection of arrays, the key value is the key value in the first array
* array array_intersect(array array1,array array2[,arrayN……])
* Find the intersection of arrays that contains equal key values, and the key value is the key value in the first array
* array array_intersect_assoc(array array1,array array2[,arrayN……])
* Find the difference set of arrays, the first array has values ​​that are not found in other arrays
* array array_diff(array array1,array array2[,arrayN……])
* Find the difference set of arrays. The first array contains equal key values ​​in values ​​that are not found in other arrays
* array array_diffassoc(array array1,array array2[,arrayN……])
* Return one or more key values ​​in the array
* mixed array_rand(array array[,int num_entries])
* Instant shuffle function
* void shuffle(array input_array)
* Sum the values ​​in the array
* mixed array_sum(array array);
* Decompose the array into a multi-dimensional array, which contains size elements
* array array_chunk(array array, int size [,boolean preserve_keys])
*/

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/632681.htmlTechArticleArrays in php are an indispensable part of our application development. Now let me learn about php myself. I would like to share some operations on arrays with you. I hope students who need to know more can go in...
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Issues
php data acquisition?
From 1970-01-01 08:00:00
0
0
0
PHP extension intl
From 1970-01-01 08:00:00
0
0
0
How to learn php well
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template