Basic knowledge of PHP array _php

Source: Internet
Author: User
Tags arrays mixed
There are many PHP functions that need to be queried by the API.

Copy Code code as follows:

<?php
/*
#数组 No Limit size: $arr [0]=1; $arr [1]=2; $arr =array ("0", "1"); $list ($num 1, $num 2) = $arr;
Array range (int low,int high[,int Step])
Low minimum number, highest high number, step stride
int Array_unshift (array array,mixed vari) array before inserting
Array_push Array Tail Add
Array_shift Array Header deletion
Array_pop Array Tail Delete
#定位数组
Boolean In_array (mixed Needle,array Haystack,[,boolean Strict])
Boolean array_key_exists (mixed Key,array array) search key
Array_search () search for associative array values
Array_keys () returns an array that contains all the keys searched for
Array_values () returns all values of the array.
#遍历数组
Mixed key (array array)
Current (array array) Gets the present array value
Array each (array array) returns the current key, value pair
Next (array array) points to the next
Prev (array array) moves to the previous
Reset (array array) moves to the first
End (array array) moves to the last
#向函数传递数组值
Boolean array_walk (array &array,callback function,[,mixed UserData])
#确定数组的大小及唯一性
Integer count (array array[,int mode]) is similar to sizeof ()
Array array_count_values (array array) grouping counts the number of occurrences per value
Array_unique () Delete duplicate values, maintain uniqueness
#排序
Array_reverse () Sequential inversion
Array_flip () Swap key and value
void sort (array array[,int sort_flags])
Sort_flgs{[sort_numberic numeric sorting],[sort_regular by ASCII],[sort_string]}
Asort () Ascending
Rsort () reverse order
Arsort () reverse order
Natsort () Natural sort
Natcasesort () case-insensitive natural sort
Ksort () key value ordering
Krsort () reverse order of key values
void Usort (array array,callback function name) user-defined sort
#合并, splitting, combining, decomposing arrays
Array_merge_recursive () Merge
Array_merge_combine () Append
Array_merge () to connect to the new array
Array_slice (array array,int offse[,int length]) split
Array_intersect (), ARRAY_INTERSECT_ASSOC () array intersection
Array_diff (), ARRAY_DIFF_ASSOC () difference set
Array_rand (), Shuffle () random array
Array_sum () sum
Array_chunk into multidimensional arrays
*/
Creates an even array of 0-20, and 2 is a step
$even =range (0,20,2);
Print array
Print_r ($even);
Determines whether an array
printf ("This is a array:%s<br/>", (Is_array ($even)? True ': ' false ');
echo "<br>";
Array header to add subkeys and print
Array_unshift ($even, 522,54);
Print_r ($even);
Define a variable, and then search in the array to show that the variable is found when it exists.
$sa = 522;
if (In_array ($sa, $even)) {
echo "Find it $sa";
};
echo "<br/>";
Searching for array key keys
if (Array_key_exists (4, $even)) {
Echo $even [4]. "Exists.";
}
echo "<br/>";
Print_r (Array_values ($even));
Traverse the print array
while ($key =key ($even)) {
echo "<br/>". $key;
Next ($even);
}
Statistical array size
echo "<br/>";
echo count ($even);
Sort
echo "<br>";
Sort ($even);
Print_r ($even);
?>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.