Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Rhinorhino on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

question about arrays

Status
Not open for further replies.

skibascott

IS-IT--Management
Joined
Mar 18, 2004
Messages
82
Location
US
When I perform an echo on $file_list in the following code, my output is simply "Array".
Code:
$list = "cd /mnt/sc_proc/video; ls *.wmv | sort"; 	  exec($list,$file_list);

Is this the actual contents of $file_list? Or does it contain all of the elements in the array? When I use the following code:
Code:
foreach ($file_list as $value)
   		{
       echo $value."<br>";
   		}

I get the contents of the array. Do I need to use this foreach function in order to perform operations on the individual elements of the array? Or can I use $file_list in the following way to perform operations on this array?
Code:
for($i=0; $i<count($file_list); $i++){ 
								if ($phpdocnum == substr($file_list[$i], 0, 7)){
									 echo $file_list[$i];
									 }else{
									 }
								}
 
foreach iterates an array, element by element until it hits the end. Each item is subjected to the code in the foreach loop.

There are array functions that allow you to use callbacks on all array elements without having to write an explicit loop. Just as an example have a look at:

In your third example above you don't perform an operation, you perform a comparison. You can use:
to find a specific element you look for.
 
Thank you. You have cleared my confusion.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top