The 1.foreach Loop statement iterates through 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", and "Web Engineer"),
Array ("Xiaochen", "123456″," "Xiao Chen", "Male", "Java Engineer")
); Declaring an indexed two-dimensional array
$html = "<table border= ' 1′width= ' 800′>"; Define string $html, the contents of the string is the <table> label of the table
foreach ($erwei _arr as $field) {
$html. = "<tr>"; Use the string operator to concatenate the original value of $html with "<tr>" into a new string, similar to the
foreach ($field as $value) {
$html. = "<td>". $value. " </td> ";
}
$html. = "</tr>";
}
$html. = "</table>";
Echo $html;
The result is
PHP's operation on the table is out of the way. Oh.
2. Common array processing functions
Array processing functions are also more important, such as random functions, sorting functions, and so on. There are roughly:
Index/value manipulation functions
In_array () Checks if there is a value in the array, Array_search () searches the array for the given value, returns the corresponding key name if successful, array_key_exists () checks if the given key name exists in the array
Array sort function
The sort () array is re-enumerated in ascending order by value, Rsort () is descending, and vice versa. Asort () Sets the value of an array in ascending order, keeping the index associated with the value, Arsort () in contrast. The Ksort () array keeps the index associated with the value in ascending order by the key name, and Krsort () is the opposite.
Array statistics/UNIQUE functions
The count () function is also mentioned before, to calculate the number of array elements in the array.
Splitting, merging, decomposing array functions
Array_combine () and Array_merge (), look directly at the code
$one _array = Array ("name", "Gender", "Age", "title");
$two _array = Array ("Small Zeng", "male", 23, "e-commerce lecturer");
echo "<p>*********array_combine () after the new array nc_array**********</p>";
$nc _array = Array_combine ($one _array, $two _array);
Print_r ($nc _array);
Result is an array ([name] + small once [gender] + male [age] + 23 [title] = e-commerce lecturer)
echo "<p>*********array_merge () after the new array nm_array**********</p>";
$NM _array = Array_merge ($one _array, $two _array);
Print_r ($nm _array);
The result is an array ([0] = name [1] + [2] + [+] [3] + [+] [4] [+] [+] [+] + [+] [+] = [5] [6] = + (7)
Random function
This everyone should be very common, some of the site's random articles, random ads, or sweepstakes, PHP is used in this principle.
The main functions are Array_rand () and Shuffle ().
Array_rand () is an array of random key names that is randomly fetched from an array, or a specified number of elements.
Shuffle () is randomly disrupting an array.
Got here. Pig Head Blog recently busy, so the update is not stable, hehe, does not matter. In this statement, part of the code is reference to my instructor Zeng Wenbing Teacher's source code.
The above is the PHP array application Base (v) content, more relevant content please pay attention to topic.alibabacloud.com (www.php.cn)!