How To Display Array Elements With Loop Get Show Array Values In PHP Tutorial



How To Display Array Elements With Loop Get Show Array Values In PHP Tutorial
 (382) Find work at Home Jobs
How To Display Array Elements With Loop Get Show Array Values In PHP Tutorial
Post Description:
Post Tags: how, to, display, array, elements, with, loop, get, show, array, values, in, php, tutorial
This Post Has Been Viewed 727 Times Since Sat Feb 23, 2008 12:55 pm Posted By hostman with 1 replies
Next Post »» How To Display Array Elements with FOR Loop
How To Display Array Elements With Loop Get Show Array Values In PHP Tutorial
ok lets say for example i have this:

/var/www/html/home/web/mydomain/root

and 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>

Leave Your Comments     [ dejar commentarios ]
  * Name     [nombre]

  * eMail (will not be published)     [coreo electronico]

* Enter Your Reply or Comments:    [commentarios]


Add Picture To Comments         [incluir foto]
YES NO             upload
Receive Replies on my Comments (An email will be sent to you when someone replies to your comments)

     

Comments and replies About How To Display Array Elements With Loop Get Show Array Values In PHP Tutorial




:: 1 :: #42919 - Reply By tech support On Sun Feb 24, 2008 12:10 pm
take a look at this tutorial. it helped me alot

how-to-index-arrays-and-show-all-the-elements-and-values-of-array