【问题标题】:for cycle - page stops loading, any alternatives?对于循环 - 页面停止加载,还有其他选择吗?
【发布时间】:2015-02-19 13:03:52
【问题描述】:

我需要回显数组,但页面停止加载。我正在运行 Wordpress。

    if($categories)  {
        for ($i=0;$i<count($categories);$i++) {
        echo $categories[$i].", ";
        }
    }

我真的不知道为什么。有没有其他方法可以做到这一点?或者将数组抓取到一个字符串中。例如

$categories[0] = "aaa";
$categories[1] = "bbb";
$string = "aaa, bbb";

(数组有未知数量的值)

【问题讨论】:

    标签: php arrays wordpress for-loop cycle


    【解决方案1】:

    这对implode() 来说是完美的,只需像这样使用它:

    echo implode(", ", $categories);
    

    举个例子:

    $categories = array("aaa", "bbb", "ccc");
    echo implode(", ", $categories);
    

    输出:

    aaa, bbb, ccc
    

    【讨论】:

      猜你喜欢
      • 2012-08-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-08-22
      • 2011-04-21
      • 1970-01-01
      相关资源
      最近更新 更多