1.The foreach loop statement traverses the two-dimensional array. This is a foreach traversal of a two-dimensional array.
$erwei_arr = array(
array("xiaoliu","123456″,"Xiao Liu","Male",29,"System Analyst") ,
array("xiaozeng","123456″,"Xiao Zeng" ,"Male",23,"Web Engineer") ,
array("xiaochen","123456″,"Xiaochen","Male",29,"Java Engineer")
); //Declare the index two-dimensional array
$html = “
”.$value.” | ”;
echo $html;
The result is
This is how PHP operates the table. hehe.
2. Commonly used array processing functions
Array processing functions are also more important, such as random functions, sorting functions, etc. Roughly:
Index/value operation function
in_array() checks whether a certain value exists in the array, array_search() searches for a given value in the array, and returns the corresponding key name if successful, array_key_exists() checks for Whether the specified key name exists in the array
Array sorting function
sort() sorts the array in ascending order by value and re-enumerates the array, rsort() is in descending order, which is the opposite. asort() sorts the array in ascending order by value, keeping the association between index and value, while arsort() does the opposite. ksort() sorts the array in ascending order by key name, keeping the association between index and value, while krsort() does the opposite.
Array Statistics/Unique Function
The count() function was also mentioned earlier. Its function is to count the number of array elements in the array.
Split, merge and decompose array functions
array_combine() and array_merge(), look at the code directly
$one_array = array("name","gender","age","position");
$two_array = array("Xiao Zeng","Male",23,"E-Commerce Lecturer");
echo "
The new array nc_array***** after *********array_combine() *****
”;The result is Array ( [name] => Xiao Zeng [gender] = > Male [Age] => 23 [Position] => E-commerce Lecturer)
echo “
The new array nm_array***** after *********array_merge() *****
”;The result is Array ([0] => Name[1] => ; Gender[2] => Age[3] => Position[4] => Xiao Zeng[5] => Male[6] => 23 [7] => E-commerce lecturer)
Random Function
This should be very common to everyone. Random articles, random advertisements, or lottery draws on some websites all use this principle in PHP.
The main functions are array_rand() and shuffle().
array_rand() randomly removes one or specified array elements from the array and returns an array containing random key names.
shuffle() is to randomly shuffle an array.
Here we are. Zhutou blog has been busy recently, so updates are unstable, haha, it doesn’t matter. I would like to state here that part of the code is based on the source code of my lecturer, Mr. Zeng Wenbing.
The above is the content of PHP array application basics (5). For more related content, please pay attention to the PHP Chinese website (m.sbmmt.com)!