0

我有一个似乎无法从中检索信息的数组。这是一个嵌套数组吗?

print_r() 结果:

Array (
    [0] => Array (
        [0] => Array (
            [title] => Hampton
            [day] => 1st and 3rd Monday
            [time] => 7:30pm
            [contact] => Jan Boyd
            [phone] => 0438 584 558
            [email] =>
        )
        [1] => Array (
            [title] => Frankston
            [day] => 1st and 3rd Wed
            [time] => 9:30am
            [contact] => Vaness Ogues-Canele
            [phone] => 0420 834 791
            [email] =>
        ) 
    )
) 

我用来尝试检索信息的代码:

foreach( $groups as $group ) { ?>
    <?php echo $group['title'] ?>
    <?php echo $group['day'] ?>
    <?php if ($group['time']) { ?>       
<?php }  ?>
4

3 回答 3

7

你试过用这个进入第一个数组吗?

foreach( $groups[0] as $group ) { ?>
    <?php echo $group['title'] ?>
    <?php echo $group['day'] ?>
    <?php if ($group['time']) { ?>       
<?php }  ?>

如果可能,您可以尝试两个 foreach 循环:

foreach( $groups as $tmp ) { ?>
    foreach ($tmp as $group) {
        <?php echo $group['title'] ?>
        <?php echo $group['day'] ?>
        <?php if ($group['time']) { ?> 
    <?php } ?>      
<?php }  ?>
于 2013-07-15T05:02:20.013 回答
1
foreach( $groups as $group ) 
 foreach( $group as $groups_re )  
  { 
    echo $groups_re['title'];
    echo $groups_re['day'] 
    if ($groups_re['time']) 
     {        
      }
  }
于 2013-07-15T05:06:06.673 回答
1

尝试这个

foreach( $groups as $group ) { 
if(is_array($group)) // it check's array or not 
{
 echo $group['title']; 
 echo $group['day']; 
 echo $group['time']; 
}
else
    echo $group;}  
于 2013-07-15T05:06:39.547 回答