Php 多数组foreach语句

Php 多数组foreach语句,php,arrays,wordpress,custom-fields,Php,Arrays,Wordpress,Custom Fields,我正在使用现有的HTML编写我的第一个PHP布局。我遇到麻烦了。我希望你能帮忙 我有3个数组 $parent = array('1' => 'parent1' , 'parent2' , 'parent3' , 'parent4' , ); $child = array('1' => 'child1' , 'child2' , 'child3' , 'child4' , ); $content = array('1' => 'content1' , 'content2' , '

我正在使用现有的HTML编写我的第一个PHP布局。我遇到麻烦了。我希望你能帮忙

我有3个数组

$parent = array('1' => 'parent1' , 'parent2' , 'parent3' , 'parent4' , );
$child = array('1' => 'child1' , 'child2' , 'child3' , 'child4' , );
$content = array('1' => 'content1' , 'content2' , 'content3' , 'content4' , );
我试图使用它们来创建一个重复列表,其中包括{$parent}、{$child}和{$content},如下所示

<?php 
  echo "<h1 id='js-overview' class='page-header'>$parent</h1>"
  echo "<h3 id='js-fotopia'>$child</h3>" 
  echo "<p>$content</p>"
?>

大概是这样的吧

for($i=1; $i<=count($parent); $i++){
      echo "<h1 id='js-overview' class='page-header'>$parent[$i]</h1>"
      echo "<h3 id='js-fotopia'>$child[$i]</h3>" 
      echo "<p>$content[$i]</p>"
}
($i=1;$i$value)的

声明


除此之外,您还可以构建一个2D数组,将父级、子级和内容全部存储在一行中。

我认为您的结构有点不合理。为什么不将三个数组合并成一个呢?有点不清楚您的父/子/内容关系是如何建立的,但这里有一个镜头:

$arr = array(
    'parent1' => array(
        'child1' => array(
            'content' => 'This is your content for child 1',
        ),
        'child2' => array(
            'content' => 'This is your content for child 2',
        ),
    ),
    'parent2' => array(
        'child1' => array(
            'content' => 'This is your content for child 1 inside of parent 2',
        )
    ),
);
然后,您可以对数组执行
foreach
,对子数组执行
foreach

foreach($arr as $parent) {
    foreach($parent as $childName => $child) {
        echo $child['content'];
    }
}

如果您的内容需要更多的结构,您可以在子数组中添加更多的键。

谢谢。。。使用了此的一个版本。。。我有一个php的方法