Welcome to the Linux community forum and interact with 2 million technical staff. 7. random array sorting involves another random sorting technology in the flash card program. In this case, you need to use shuffle () function to achieve random sorting of array items. $ Capitalsarray (ArizonaPhoenix, AlaskaJuneau, Alabama
Welcome to the Linux community forum and interact with 2 million technical staff> go to 7. random array sorting involves another random sorting technology in the flash card program. Then you need to use shuffle () function to achieve random sorting of array items. $ Capitals = array ('arizona '= 'phoenix', 'alaska '= 'juneau', 'alabama
Welcome to the Linux community forum and interact with 2 million technicians>
7. random array sorting
Another random sorting technique is involved in the flash card program. In this case, you need to use the shuffle () function to implement random sorting of array projects.
$ Capitals = array (
'Arizona '=> 'phoenix ',
'Apache' => 'juneau ',
'Babama' => 'mongomery'
);
Shuffle ($ capitals );
If you do not need to disrupt the array order and want to randomly select a value, use the array_rand () function.
8. Check whether the key and value exist.
You can use the in_array () function to determine whether an array element exists.
$ Capitals = array (
'Arizona '=> 'phoenix ',
'Apache' => 'juneau ',
'Babama' => 'mongomery'
);
If (in_array ("Juneau", $ capitals ))
{
Echo "Exists! ";
} Else {
Echo "Does not exist! ";
}
Few people know that this function can also determine whether an array key exists. At this point, it functions the same as the array_key_exists () function.
$ Capitals = array (
'Arizona '=> 'phoenix ',
'Apache' => 'juneau ',
'Babama' => 'mongomery'
);
If (array_key_exists ("Alaska", $ capitals ))
{
Echo "Key exists! ";
} Else {
Echo "Key does not exist! ";
}
9. Search for Arrays
You may want to search for Array resources, so that you can easily search associated States using a specific state government. You can use the array_search () function to search for arrays.
$ Capitals = array (
'Arizona '=> 'phoenix ',
'Apache' => 'juneau ',
'Babama' => 'mongomery'
);
$ State = array_search ('juneau ', $ capitals );
// $ State = 'alaska'
10. Standard PHP Library
The Standard PHP Library (SPL) provides developers with many data structures, iterators, interfaces, exceptions, and other functions not available in the previous PHP language, these functions can be used to traverse arrays through object-oriented syntax.
$ Capitals = array (
'Arizona '=> 'phoenix ',
'Apache' => 'juneau ',
'Babama' => 'mongomery'
);
$ ArrayObject = new ArrayObject ($ capitals );
Foreach ($ arrayObject as $ state => $ capital)
{
Printf ("The capital of % s is % s
", $ State, $ capital );
}
// The capital of Arizona is Phoenix
// The capital of Alaska is Juneau
// The capital of Alabama is Montgomery
This is only one of the many great functions of SPL. You must read the PHP manual to learn more.
[1] [2]