Generally, sorting is performed by sorting the database or nosql (eg: redis) and then outputting it to the program. However, sometimes we need to sort the array directly through PHP, objects and arrays are the most used for storing data in PHP, but
1. What is an array?An array is a collection of data. It organizes a series of data to form an operable whole. Each object in the array contains two items: Key and value.Ii. Declare dataThere are two ways to declare arrays in PHP:First, apply the
1. character location search function:Strpos ($ str, search, [int]): searches for the first position of search in $ str starting from int;Stripos ($ str, search, [int]): the position where the string first appears in another string. This function is
This article mainly introduces the sorting method of php arrays containing Chinese characters. if you need a php array, you can refer to the Chinese sorting method of php arrays. Generally, the file format is utf8, but it cannot be sorted directly
This article provides a detailed analysis of the functions of array elements in PHP in ascending, descending, and re-sorting. For more information, see
1. quickly create an array function range ()For example, the range () function can quickly create
This article mainly introduces the two-dimensional array in PHP how to achieve, interested in the friend's reference, I hope to help you.
PHP in two-dimensional array ordering, you can use the PHP built-in function Uasort ()
Example one:
Use a user-
This article mainly introduces the sorting method of php arrays containing Chinese characters. If you need a php array, you can refer to the Chinese sorting method of php arrays. Generally, the file format is utf8, but it cannot be sorted directly
First, create a new arrayThe array has no size limit, so you can create an array simply by creating a reference, for example: $state [0]= ' 111 '; $state [1]= ' 222 '; If the index value is a numeric index and is incremented, the index value can
Awk was finally able to get started, so he tidied up the article, mostly from the Internet.First, bash supports one-dimensional arrays (which do not support multidimensional arrays) and does not limit the size of arrays. In the shell, the array is
About sorting generally we are in the database or NoSQL (Eg:redis) First order and then output to the program directly to use, but sometimes we need to sort by PHP directly to the array, and in PHP to store data to use the most is the object and
Sort break Index Ascending value sorting
Rsort Breaking index Descending value sort
Asort Keep Index Ascending value sort
Arsort Keep Index Descending value sort
Ksort Keep index Ascending key value sort (key)
Krsort Keep index Descending key
In the retrieved array, the first three small three units, non-continuous index array
$arr =array(11=>2530,13=>8922,26=>250,77=>250,88=>1230,99=>12);
How can we retrieve the smallest three items of the above array:
array(99=>12,26=>250,77=>250)
PHP array operations
To access the content of a variable, you can directly use its name. If the variable is an array, you can use a combination of variable names and keywords or indexes to access its content.
Like other variables, you can use
About sorting generally we are in the database or NoSQL (Eg:redis) First order and then output to the program directly to use, but sometimes we need to sort by PHP directly to the array, and in PHP to store data to use the most is the object and
1, quickly create an array of function range ()For example, the range () function can quickly create arrays of numbers from 1 to 9:
Copy CodeThe code is as follows:
$numbers =range (1,9);
echo $numbers [1];
?>
Of course, using range (9,1) creates
1 Find the character position function:
Strpos ($str, Search,[int]): Find the first position of search in $str starting with int;
Stripos ($str, search,[int]): function returns the position of the first occurrence of a string in another string. This
This article mainly introduces how to learn PHP arrays [experience]. For more information, see
PHP has many array functions to facilitate array operations.
Definition:
Each object in the array contains two items: key and value. you can use the
PHP simple array Sorting method for everyone to learn the reference.
PHP does not know how to compare two arrays and needs to create a way to compare them.
First, the initialization of the numeric index array
Copy the Code code as follows:
$arr =
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.