Categories:
.NET (357)
C (330)
C++ (183)
CSS (84)
DBA (2)
General (7)
HTML (4)
Java (574)
JavaScript (106)
JSP (66)
Oracle (114)
Perl (46)
Perl (1)
PHP (1)
PL/SQL (1)
RSS (51)
Software QA (13)
SQL Server (1)
Windows (1)
XHTML (173)
Other Resources:
How to Loop through an Array
How to Loop through an Array? - PHP Script Tips - Understanding PHP Arrays and Their Basic Operations
✍: 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
2007-04-20, 5234👍, 0💬
Popular Posts:
What is difference between custom JSP tags and JavaBeans? Custom JSP tag is a tag you defined. You d...
.NET INTERVIEW QUESTIONS - Where do you specify session state mode in ASP.NET ? The following code e...
How To Return Top 5 Rows? - MySQL FAQs - SQL SELECT Statements with JOIN and Subqueries If you want ...
Describe different elements in Static Chart diagrams ? Package: - It logically groups element of a U...
How To Write a Minimum Atom 1.0 Feed File? - RSS FAQs - Atom Feed Introduction and File Generation I...