doukanmang3687 2014-08-06 10:41
浏览 66
已采纳

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

I have four arrays that I get from the database unserialize inside a loop, and than get a single value from a loop inside this loop :) Code below:

<?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;
  }
}

?>

Of course when i echo it i get something like: mayseptember19901996College NameAnother CollegeITWriter

What I need is to loop it somehow so i can get the following:

May 1990

College Name

IT


September 1996

Another College

Writer

How could I do that?

Thank you!

  • 写回答

2条回答 默认 最新

  • douju2474 2014-08-06 10:50
    关注

    just change the order and ad some html elements ..everything is done .updated

       <?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>';
      }
    ?>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 乌班图ip地址配置及远程SSH
  • ¥15 怎么让点阵屏显示静态爱心,用keiluVision5写出让点阵屏显示静态爱心的代码,越快越好
  • ¥15 PSPICE制作一个加法器
  • ¥15 javaweb项目无法正常跳转
  • ¥15 VMBox虚拟机无法访问
  • ¥15 skd显示找不到头文件
  • ¥15 机器视觉中图片中长度与真实长度的关系
  • ¥15 fastreport table 怎么只让每页的最下面和最顶部有横线
  • ¥15 R语言卸载之后无法重装,显示电脑存在下载某些较大二进制文件行为,怎么办
  • ¥15 java 的protected权限 ,问题在注释里