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
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
Post Description: how to display array elements with loop get show array values in php tutorial
POST# 720
Posted On: Fri Feb 29, 2008 12:01 pm
web hosting
Topic: 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>


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

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

What do you think?

* name:  

* email:  

* Please enter comments:


Receive Replies on my Comments
(An email will be sent to you when someone replies to your comments)

Add image to comments
yes no             upload
     
  1. Warning: Mysql_fetch_array(): Supplied Argument Is Not A Valid MySQL Result
  2. Simple Array Example Learn PHP Programming Creating Arrays Learn Tutorial
  3. How To Create Make PHP Forms Using Form Arrays Tutorial
  4. How To Count And Break A Word Into An Array In Php Tutorial Guide
  5. How To Display Array Contents
  6. PHP Using For Loop To Display The Contents Of An Array
  7. How To Count Array Values Php Counting Arrays Holds Variables Script
  8. How To Use For Loop In Php Using Array Tutorial Sample Script
  9. Count And Display Words In A String Into Array Php Sentence Word
  10. How To Make Array Variable Global In PHP Function
  11. How To Count Elements In An Array Find How Many Values Arrays
  12. How To Check If Array Is Empty Or False Value
  13. How To Display Array Elements With Loop Get Show Array Values In PHP Tutorial
  14. How To Display Array Elements With FOR Loop
  15. Php Form Using Array For Field Name Template User Information
  16. Getting Array Elements Values With While Loop Show Display
  17. Display Array Elements Values With Loop
  18. How To Index Arrays And Show All The Elements And Values Of Array
  19. Php Show Values Array
  20. Php Html Display Array
  21. Making An Array From A Mysql Query