how to display elements in an array in foreach loop

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

kingconnections
Forum Contributor
Posts: 137
Joined: Thu Jul 14, 2005 4:28 pm

Post by kingconnections »

OK so the loop around my other for loops pretty much got me no where. So what i did was this. Note all the commented code is orginal ouput loop.

Code: Select all

foreach ($site_array as $site_key => $site_val) 

{ 
$row_color = ($row_count % 2) ? $color1 : $color2;  // row alternating color stuff

	echo "<tr bgcolor=$row_color><td><a href=test2.php?scode=$site_key>$site_key</a></td>";

                      foreach ($current_patchs as $key => $patch_val) // this one puts the items in correct                  just not the right value printed.  

    //foreach ($site_val as $site_name => $site_data)  // normal output loop for value
   { 
                          
    		echo"<td>$site_val[$patch_val]</td>";	// This line just prints the "Array" item in the correct colmn! Right here is where I need the next zero element.  
    		

    // foreach ($site_data as $key => $value) // normal output loop for value
      // { 
                
        //   echo "<td>$value</td> "; 
                       
        //} // 3rd dimension 
       
    } // 2nd dimension 
    echo" </tr>";
      $row_count++;   //
} // 1st dimension

This produces this output:

The output is in the correct columns, I just need to print the final array element there? Which in the normal output is the last loop.

I am getting an invalid index error, LOL thats is because that index doesn't exist. LOL


Image
kingconnections
Forum Contributor
Posts: 137
Joined: Thu Jul 14, 2005 4:28 pm

Post by kingconnections »

OK - so i think I found my solution.... what if i use the normal multi dimensional array loops to output as mentioned before, but before I print the item I do another loop to refernce my patches array with a isset statement for the key. So LOOP thru these items..


patch1,
patch 2,
patch 3,


If any of these are not set
then insert patch# whatver and set value to 0.



I found it on this page .

http://us3.php.net/manual/en/function.isset.php

Will that work?
Post Reply