- Forums
- Tutorial And Guides
- How To Display Array Elements With Loop Get Show Array Values In PHP Tutorial
This Page Contains information about How To Display Array Elements With Loop Get Show Array Values In PHP Tutorial By wallpaperama in category Tutorial And Guides with 2 Replies. [1430], Last Updated: Sat May 18, 2024
wallpaperama
Sat Feb 23, 2008
2 Comments
6351 Visits
ok lets say for example i have this:
/var/www/html/home/web/mydomain/rootand i want to only capture mydomain out of all this and i want to break this directory path into an array so var would be one element of the array. with php i can do this
first i will creat a string with the value of my script path:
$path = getenv('SCRIPT_FILENAME')next i want to make $path into an array:
$path = explode("/", $path );now i have created an array and now its time to display each element into their individual value, i will use a for loop for this:
for($i =0; $i < count($words); $i++) {
echo $words[$i]."<br>";
}and now it will display each element using the loop
if you want to try it yourself copy and paste the code below into your text editor and save it as array.php and upload to your php website and see it for yourself.
PHPCODE:
<h1>DISPLAY ARRAY ELEMENTS TUTORIAL </h1>
<strong>Tutoral by <a href="http://www.webune.com">www.webune.com</a></strong><br><br>
<?
## THIS TUTORIAL CREATED BY WWW.WEBUNE.COM LICENSED THROUGH WWW.WALLPAPERAMA.COM
$dir_fs_www_root = getenv('SCRIPT_FILENAME');
echo "<strong>Script Path: ".$dir_fs_www_root."</strong><br><br>";
echo "<strong>Array Elements:</strong><br><br>";
$words= explode("/", $dir_fs_www_root );
for($i =0; $i < count($words); $i++) {
echo "<strong>$words[$i]</strong> = ";
echo $words[$i]."<br>";
}
?>
<br><br>
<div align="center">
<a href="http://www.webune.com">
<img src="http://www.webune.com/images/headers/default_logo.jpg" border="0">
</a></div>
how-to-index-arrays-and-show-all-the-elements-and-values-of-array