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, ∼2364🔥, 0💬
Popular Posts:
How to view API details on the Publisher Dashboard of an Azure API Management Service? You can follo...
How to add images to my EPUB books Images can be added into book content using the XHTML "img" eleme...
How to login to Azure API Management Publisher Dashboard? If you have given access permission to an ...
How to how to use matched string and groups in replacements with re.sub()? When calling the re.sub()...
How to build a PHP script to dump Azure AD 2.0 Authentication Response? If you are use the Azure-AD-...