Tools, FAQ, Tutorials:
Looping through an Array in PHP
How to Loop through an Array in PHP?
✍: FYIcenter.com
The best way to loop through an array is to use the "foreach" statement. There are two forms of "foreach" statements:
Here is a PHP script on how to use "foreach" on an array:
<?php
$array = array("Zero"=>"PHP", "One"=>"Perl", "Two"=>"Java");
$array["3"] = "C+";
$array[""] = "Basic";
$array[] = "Pascal";
$array[] = "FORTRAN";
print("Loop on value only:\n");
foreach ($array as $value) {
print("$value, ");
}
print("\n\n");
print("Loop on key and value:\n");
foreach ($array as $key=>$value) {
print("[$key] => $value\n");
}
?>
This script will print:
Loop on value only: PHP, Perl, Java, C+, Basic, Pascal, FORTRAN, Loop on key and value: [Zero] => PHP [One] => Perl [Two] => Java [3] => C+ [] => Basic [4] => Pascal [5] => FORTRAN
⇒ Order of Array Values in PHP
2017-02-03, ∼2416🔥, 0💬
Popular Posts:
How to search for the first match of a regular expression using re.search()? The re.search() functio...
How to use "json-to-xml" Azure API Policy Statement? The "json-to-xml" Policy Statement allows you t...
Can Two Forms Be Nested? Can two forms be nested? The answer is no and yes: No. You can not nest two...
Where to find tutorials on Using Azure API Management Publisher Dashboard? Here is a list of tutoria...
Where to get the detailed description of the json_encode() Function in PHP? Here is the detailed des...