合并2个数组返回空php

时间:2014-12-23 07:30:59

标签: php arrays

我正在存储2个这样的数组:

$gooff = array();

for($j=1;$j<=count($search_res);$j++)
{
   $post_id = $wpdb->get_results("SELECT DISTINCT post_id,meta_value from wp_postmeta Where meta_value"); 

$gooff = array_merge($post_id, $gooff);

}

但是打印会导致结果为空;

print_r($gooff); // Returning empty.

我认为我做的一切都是正确的。那导致这个空结果的是什么?是的,我的post_id数组中有值。

post_id结果:

Array
(
    [0] => stdClass Object
        (
            [post_id] => 1129
            [meta_value] => java,php,html,css,mysql,jsp,cricket
        )

    [1] => stdClass Object
        (
            [post_id] => 1143
            [meta_value] => PHP,AJAX,MY,PROFILE,JAVA
        )

    [2] => stdClass Object
        (
            [post_id] => 1149
            [meta_value] => MY,PROFILE,PHP,DEVELOPER
        )

    [3] => stdClass Object
        (
            [post_id] => 1202
            [meta_value] => php,html&css
        )

    [4] => stdClass Object
        (
            [post_id] => 1209
            [meta_value] => php,html,wordpress,php,html,wordpress,php,html,wordpress,php,html,wordpress
        )

    [5] => stdClass Object
        (
            [post_id] => 1213
            [meta_value] => php,html,css,wordpress,jquery
        )

    [6] => stdClass Object
        (
            [post_id] => 1223
            [meta_value] => PHP,C++,C#,.Net,MYSQL
        )

)
Array
(
    [0] => stdClass Object
        (
            [post_id] => 1129
            [meta_value] => java,php,html,css,mysql,jsp,cricket
        )

    [1] => stdClass Object
        (
            [post_id] => 1143
            [meta_value] => PHP,AJAX,MY,PROFILE,JAVA
        )
)

1 个答案:

答案 0 :(得分:0)

你的sql查询是返回对象而不是数组。在get_results中将第二个参数作为ARRAY_A传递。

$post_id = $wpdb->get_results("SELECT DISTINCT post_id,meta_value from wp_postmeta Where meta_value",ARRAY_A);