function返回数组返回null

i got a php function in Wordpress that get serialized user meta : like this

    function get_allowwed_tournees_ids(){
    $tournees = get_user_meta($this->ID, 'tournees',true);
    $tournees = unserialize($tournees);

    $tournees_ids = array();

    foreach ($tournees as $key => $value) {
        array_push($tournees_ids, $key);
    }

    var_dump($tournees_ids);
    return $tournee_ids;
}

get_allowwed_tournees_ids() is in a class that extends WP_User and when i want to call it :

$id_tournees = $current_user->get_allowwed_tournees_ids();
var_dump($id_tournees);

the var_dump inside the function returns me the unserialised array, and the second var_dump outside the function returns null.

Any idea ?? Thanks !

duandao3265
duandao3265 你不需要使用unserialize我猜cozget_usermeta函数返回你的数组或多维数组。
6 年多之前 回复

1个回答



因为您要返回永远未定义的$ tournee_ids。 我认为你应该</ p>

 返回$ tournees_ids; 
</ code> </ pre>
</ div>

展开原文

原文

Because you are returning $tournee_ids which is never defined. I think you should

return $tournees_ids;

    立即提问