Hi all,

I have a 2 dimentional array. What im trying to do is pull out the relevant bits and slot them under their correct segment, which works for tier one. If totally forgotten how to loop through the 2nd tier of the array. i know it needs to go in the else, but my brain is fried

my code so far is as follows

echo "<table border=\"1\">";
echo "<tr>";
foreach ($headers as $header){
	
	echo "<td>" . $header . "</td>";
}
echo "</tr>";

$SQL = "SELECT converted_text FROM forms_subscribed";
$results = tep_db_query($SQL);

while ($row = tep_db_fetch_array($results)){
	
	$entry = unserialize($row['converted_text']);
	
	foreach ($headers as $key=> $header){
		
		
				if ((array_key_exists($header, $entry)) && ($entry[$header] != 'Array')){
					echo "<td>" . $entry[$header] . "</td>";
				
				} else {
				
				echo "<td>-</td>";	
				}
	}
	
	echo "</tr>";
}

echo "</table>";

May be try this to loop your second level of array.

if ((array_key_exists($header, $entry)) && ($entry[$header] != 'Array')){
  echo "<td>";
  foreach($entry[$header] as $key => $value) {
      echo $key . ' - ' . $value . "<br />";
  }
  echo "</td>";
}

ive included 2 example arrays. As you can see, they may have extra elements. Would you be able to provide an example of how you would echo that into a table?

im rather stuck

Array
(
    [firstname] => john
    [lastname] => smith
    [email] => js@hotmail.com
    [gender] => Male
    [dob] => Array
        (
            [day] => 
            [month] => 
            [year] => 
        )

    [interested] => Array
        (
            [Haircare] => 1
            [Hair removal] => 1
            [Shaving] => 1
            [Grooming] => 1
        )

    [agree] => 1
    [x] => 104
    [y] => 17
)




Array
(
    [firstname] => Chris
    [lastname] => Jones
    [email] => example@gmail.com
    [dob] => Array
        (
            [day] => 16
            [month] => 3
            [year] => 1954
        )

    [interested] => Array
        (
            [Hair removal] => 1
            [Shaving] => 1
        )

    [agree] => 1
    [x] => 53
    [y] => 15
)

This may not be exact answer, but might be helpful.

<tr>
  <td>FirstName</td>
  <td>LastName</td>
  <td>Email</td>
  <td>Gender</td>
  <td>DOB</td>
  <td>Interested</td>
</tr>
<?php
   foreach($entry as $key => $value) { // $value will contain your 2 example array values
?>
    <tr>
       <td><?php echo $value['firstname']; ?></td>
       <td><?php echo $value['lastname']; ?></td>
       <td><?php echo $value['email']; ?></td>
       <td><?php echo $value['gender']; ?></td>
       <td><?php echo (isset($value['dob']['day']) && !empty($value['dob']['day']) ? implode("/", array_values($value['dob'])) : ''); ?></td>
       <td><?php echo implode(", ", array_keys($value['interested'])); ?></td>
    </tr>
<?php
   }
?>
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.