我有一个看起来像这样的数组对象,并存储在变量中 $named_array
Array
(
[results] => Array
(
[0] => Array
(
[date] => 2013-15-6
[position] => 5
[person] => John
)
[1] => Array
(
[date] => 2013-15-6
[position] => 3
[person] => Alex
)
)
)
另一个称为$post
WordPress的post对象数组,与$posts = get_posts(array(....
I一起调用,然后每个循环都有一个foreach,其中$ post为变量。
在我的foreach循环中,我尝试了以下方法来组合数组,但无法正常工作。
$combinedData = array_merge($post, $named_array);
print_r($combinedData);
我可以用print_r($ post);查看我的post对象数组。在foreach循环以及named_array中。将named_array添加到post数组的正确函数是什么?
谢谢
$posts
正如您提到的,是一个对象数组
$post
是一个对象,而不是数组,因此您不能使用 array_merge()
如果要将结果作为新属性添加到$post
,则正确的方法是:
$post->results = $named_array['results'];
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句