Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/268.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
从函数PHP返回无序列表内容_Php_Arrays_List_Return_Unordered - Fatal编程技术网

从函数PHP返回无序列表内容

从函数PHP返回无序列表内容,php,arrays,list,return,unordered,Php,Arrays,List,Return,Unordered,我非常感谢任何人在这方面的帮助。基本上,我想从其他数组中创建一个列表数组,以绕过wordpress的do_shortcode函数的限制。我使用了很多函数 问题的长版本: 当前代码如下所示: /* These are the functions contained in a functions file */ function output_entry_data() { $postdate = get_the_date('j/n/y'); $entrytitle =

我非常感谢任何人在这方面的帮助。基本上,我想从其他数组中创建一个列表数组,以绕过wordpress的do_shortcode函数的限制。我使用了很多函数

问题的长版本:

当前代码如下所示:

    /* These are the functions contained in a functions file */

    function output_entry_data() {
   $postdate = get_the_date('j/n/y');
   $entrytitle = get_the_title();

return ('<li><p class="postmeta">'. $postdate. '</p><h3>'. $entrytitle. '</h3></li>');
    }



    function output_month_data($entrynomax = '', $month = '', $entrydata = '') {
   $entryno = 1;

   while($entryno <= $entrynomax) {
    echo $entrydata[$entryno];
    $entryno++;
   }

    }


    function output_year_data($monthlynomax = '', $year = '', $monthlydata = '') {
   $monthno = 1;

   while($monthno <= $monthnomax) {
    echo do_shortcode('<h4>[slider title="'. $month. '"]</h4><ul>'. $monthlydata[$monthno]. '</ul>[/slider]');
    $monthno++;
   }

    }

    /* This is from a loop that determines whether you have reached the end of a month or a year */

    $entrydata[$entryno] = output_entry_data();
    $entrynomax = $entryno;

    $monthlydata = array($monthno => $monthno);
    $monthlydata[$monthno] = return(output_month_data($entrynomax, $month, $entrydata));
    $monthlynomax = $monthno;

    $annualdata[$yearno] = array($yearno => $yearno);
    $annualdata[$yearno] = return(output_year_data($monthlynomax, $year, $monthlydata));

    $entryno = 1;
    $monthno = 1;
    $yearno++;
    $yearo = get_the_date('Y');

    /* The idea is that all the data gets outputted at the end of the loop like this: */

    $yearnomax = $yearno;

    echo ('<ul>');

   $yearno = 1;

   if($yearno <= $yearnomax) {
    echo do_shortcode('<h3>[expand title ="'. $year. '"]</h3><ul>'. $annualdata[$yearno]. '</ul>[/expand]');
    $yearno++;
   }

    echo('</ul>');
/*这些是函数文件中包含的函数*/
函数输出\输入\数据(){
$postdate=获取日期('j/n/y');
$entrytitle=获取标题();
返回(“
  • ”.$postdate.

    ”.$entrytitle.
  • ); } 函数输出\u月\u数据($entrynomax='',$month='',$entrydata=''){ $entryno=1; 而($entryno$monthno); $monthlydata[$monthno]=返回(输出月份数据($entrynomax,$month,$entrydata)); $monthlynomax=$monthno; $annualdata[$eargeno]=数组($eargeno=>$eargeno); $annualdata[$eargo]=返回(输出年数据($monthlynomax,$year,$monthlydata)); $entryno=1; $monthno=1; $o++; $yearo=获取日期('Y'); /*其思想是所有数据都在循环结束时输出,如下所示:*/ $deargenomax=$deargeno; 回声(“
      ”); $o=1; 如果($o是的,这(很容易)是可能的。至少有两种方法

    • 连接字符串并返回结果字符串:

      function output_month_data($entrynomax = '', $month = '', $entrydata = '') {
        $entryno = 1;
      
        $return = '';
        while($entryno <= $entrynomax) {
          $return .= $entrydata[$entryno]; # concatenate strings
          $entryno++;
        }
      
        return $return;
      }
      
    • 是的,这(很容易)是可能的。至少有两种方法

    • 连接字符串并返回结果字符串:

      function output_month_data($entrynomax = '', $month = '', $entrydata = '') {
        $entryno = 1;
      
        $return = '';
        while($entryno <= $entrynomax) {
          $return .= $entrydata[$entryno]; # concatenate strings
          $entryno++;
        }
      
        return $return;
      }