PHP,WordPress:来自多个数组的循环信息

PHP,WordPress:来自多个数组的循环信息,php,arrays,wordpress,loops,Php,Arrays,Wordpress,Loops,我有四个数组,我从循环中的数据库中获取,然后在循环中从循环中获取一个值:)代码如下: <?php // MONTH $eduGraduationDateMonth = get_post_custom_values('rbeduendmonth'); // YEAR $eduGraduationDateYear = get_post_custom_values('rbeduendyear'); // PLACE $eduPlace = get_post_custom_values('rbe

我有四个数组,我从循环中的数据库中获取,然后在循环中从循环中获取一个值:)代码如下:

<?php

// MONTH
$eduGraduationDateMonth = get_post_custom_values('rbeduendmonth');
// YEAR
$eduGraduationDateYear = get_post_custom_values('rbeduendyear');
// PLACE
$eduPlace = get_post_custom_values('rbeduplace');
// FACULTY
$eduFaculty = get_post_custom_values('rbedusubject');

foreach($eduGraduationDateMonth as $eduMonthValue){
  $eduMonthUnser = unserialize($eduMonthValue);
  foreach($eduMonthUnser as $eduMonthUnserValue){
    echo $eduMonthUnserValue;
  }
}

foreach($eduGraduationDateYear as $eduYearValue){
  $eduYearUnser = unserialize($eduYearValue);
  foreach($eduYearUnser as $eduYearUnserValue){
    echo $eduYearUnserValue;
  }
}

foreach($eduPlace as $eduPlaceValue){
  $eduPlaceUnser = unserialize($eduPlaceValue);
  foreach($eduPlaceUnser as $eduPlaceUnserValue){
    echo $eduPlaceUnserValue;
  }
}

foreach($eduFaculty as $eduFacultyValue){
  $eduFacultyUnser = unserialize($eduFacultyValue);
  foreach($eduFacultyUnser as $eduFacultyUnserValue){
    echo $eduFacultyUnserValue;
  }
}

?>

当然,当我回应它时,我会得到这样的信息:可能是1996年9月大学名称另一位大学编剧

我需要的是以某种方式循环它,这样我可以得到以下结果:

1990年5月

学院名称


1996年9月

另一所学院

作者

我怎么能这么做


谢谢大家!

我没有在wordpress上工作过,但我快速查看了文档:

您可以使用
get\u post\u custom()
函数,然后在上面循环。在循环的每个迭代中,访问该迭代的所有键


希望这有帮助。

只需更改顺序并添加一些html元素。一切都已完成。已更新

   <?php

// MONTH
$eduGraduationDateMonth = get_post_custom_values('rbeduendmonth');
// YEAR
$eduGraduationDateYear = get_post_custom_values('rbeduendyear');
// PLACE
$eduPlace = get_post_custom_values('rbeduplace');
// FACULTY
$eduFaculty = get_post_custom_values('rbedusubject');

foreach($eduGraduationDateMonth as $eduMonthValue){
  $eduMonthUnser = unserialize($eduMonthValue);

}

foreach($eduGraduationDateYear as $eduYearValue){
  $eduYearUnser = unserialize($eduYearValue);

}

foreach($eduPlace as $eduPlaceValue){
  $eduPlaceUnser = unserialize($eduPlaceValue);

}

foreach($eduFaculty as $eduFacultyValue){
  $eduFacultyUnser = unserialize($eduFacultyValue);

}
foreach($eduMonthUnser as $key =>$value){
    echo $value.'<br>';
    echo $eduYearUnser[$key].'<br>'; 
    echo $eduPlaceUnser[$key].'<br>';
    echo $eduFacultyUnser[$key].'<br>';
  }
?>


如果您要使用键、值对,您可以轻松实现您想要的。这需要在一个循环中完成。因此,我是否应该像foreach($key=>$eduMonthValue)那样执行
foreach($eduGraduationDateMonth)
。或者我应该在哪里添加一个
$key
东西?对于使用key、value的数组中的所有四个变量,请确保为所有四个变量(即0、1、2…)分配相同的key。。。。为简化起见,请编写一个foreach,其中尝试如下foreach($educraduationdatemonth as$key=>$eduMonthValue){echo$eduMonthValue.“$educraduationdateyear[$key]”“
”;“echo$educfaculty[$key]”我对此有点困惑:)你能给我举个简单的例子吗,这样我就可以理解如何为这些变量组成数组并分配键和值了?在使用这个get_post_custom_values()时,请确保你得到的数组中所有四个变量的键都是相同的。
get_post_custom()
在我记忆中不适用于数组,而是返回数组。有一个名为
get\u post\u custom\u values()
的属性可以从数据库中获取数组。我不明白。文档说它将返回“作为多维数组,包含当前帖子的所有自定义字段”。“试试看。我很想知道它是否真的不起作用。哦,我明白你的意思了,是的,我的错,
get\u post\u meta()
对数组不起作用。但是
get\u post\u custom()
将从表单中的所有字段返回信息,并且该表单有大约100个输入字段,用户可以动态添加无限数量的额外输入,因此如果我使用
get\u post\u custom()
:)将很难处理所有这些信息不,这只会在表单中添加换行符,我需要的是关于一所大学的信息,而不是关于第二所大学的信息等等。好的,编辑好的一个非常好,谢谢!)这行得通,但我不喜欢。在最后一个循环中,$key基于$eduMonthUnser。如果$key在年份、地点或教员中不存在怎么办?如果您的表单编码正确,那么您应该不会有任何问题。为了保证健壮性,最好检查$key是否存在。