PHP - 如何阵列组合成while循环,一个阵列? [英] PHP - How to combine arrays into one array in while loop?

查看:108
本文介绍了PHP - 如何阵列组合成while循环,一个阵列?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这样的code,给了我 POST_PERMALINK 在一个while循环。

I have this code which gives me post_permalink in a while loop.

<?php 
  $value[] = array();
    while ($the_query->have_posts()) : $the_query->the_post()
                $value[] =array(
                    'post_permalink' => get_permalink()
                );

 endwhile; ?>

现在的事情是,我得到了链接

Now the thing is that I'm getting the links as

    Array ( [0] => Array ( [post_permalink] => link ) 
            [1] => Array ( [post_permalink] => link ) 
            [2] => Array ( [post_permalink] => link ) 
            [3] => Array ( [post_permalink] => link ) )

我想这是方式:

        Array ( [post_permalink] => link  
                [post_permalink] => link 
                [post_permalink] => link 
                [post_permalink] => link  )

即:所有在一个阵列中,而不是四个子阵列的联系。请帮助!

i.e: All of the links in one array instead of four subarrays. Please help!

推荐答案

您不能有一个数组你想要它,因为每个阵列键必须是唯一的方式。这将工作:

You can't have an array the way you want it because each array key must be unique. This will work:

$values = array();
while($the_query->have_posts()) : $the_query->the_post();
    $values[] = get_permalink();
endwhile;

这篇关于PHP - 如何阵列组合成while循环,一个阵列?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆