PHP-如何在while循环中将数组组合成一个数组?
我有一个代码,它在一个while循环中为我提供了PHP-如何在while循环中将数组组合成一个数组?,php,arrays,multidimensional-array,while-loop,Php,Arrays,Multidimensional Array,While Loop,我有一个代码,它在一个while循环中为我提供了post\u permalink <?php $value[] = array(); while ($the_query->have_posts()) : $the_query->the_post() $value[] =array( 'post_permalink' => get_permalink() )
post\u permalink
<?php
$value[] = array();
while ($the_query->have_posts()) : $the_query->the_post()
$value[] =array(
'post_permalink' => get_permalink()
);
endwhile; ?>
我希望它是这样的:
Array ( [post_permalink] => link
[post_permalink] => link
[post_permalink] => link
[post_permalink] => link )
i、 e:一个数组中的所有链接,而不是四个子数组。请帮忙 由于数组键是唯一的,因此无法提供所需的示例
foreach($value[0] as $k=>$v)
$result[$k]=$v
您可能需要以下内容:
$value['post_permalink'][] = get_permalink();
不能按所需方式使用数组,因为每个数组键必须是唯一的。这将有助于:
$values = array();
while($the_query->have_posts()) : $the_query->the_post();
$values[] = get_permalink();
endwhile;
您想要的结果多次具有相同的索引。我认为这不是你真正想要的。你的数组必须有唯一的键。真的没有办法解决这个问题。是的,我希望每个值都有相同的索引,如果可能的话“如果可能”不是。在尝试一大堆事情之前,你可能应该花更多的时间弄清楚你到底想完成什么,要实现这一点,结果应该是什么?$u查询前面的冒号是做什么的?我以前从未见过这种语法。@max.weller这是Wordpress中的标准循环语法
$values = array();
while($the_query->have_posts()) : $the_query->the_post();
$values[] = get_permalink();
endwhile;