Loop through an Array using Foreach Function in PHP
You can loop through an array using foreach function. So instead of using:
<?php
$names = array("Paul","Maria","David","Lucy","Ana");
$i=0
while($names[$i] == true)
{
echo("$names[$i]");
$i++;
}
?>
You can be more efficient and use foreach:
<?php
$names = array("Paul","Maria","David","Lucy","Ana");
foreach ($names as $myname)
{
echo("$myname");
}
?>
Related Articles
- Add an Automatic / Dynamic Copyrighted Year Message in PHP
- Php Mail Function with Html Header
- How to check if an email address exists without sending an email?
- Pass Array from Multipart/Form-data Post Method or Query String with Foreach Function in PHP
- Use in_array function to check if a value exists in an array using PHP
- Delete File or an Image from the Server using PHP
- Encrypt Decrypt using the Rijndael 256 Mcrypt Function in PHP
- Encrypt Decrypt using the Rijndael 256 Mcrypt Class in PHP
