【发布时间】:2014-09-21 01:44:28
【问题描述】:
我不知道为什么我的函数总是返回 NULL。 return 之前的 var_dump($args) 显示 $args 中的项目太多。但是当我在另一个地方调用这个函数时,它返回 NULL。有人能帮我吗?谢谢。
在评论中我解释了情况。
function LBE_result_hompage_search_ecole_map()
{
// Get department code when user click map
$code = $_POST['code'];
// Query data from database
global $wpdb;
$table_name = $wpdb->prefix.'utils_ville';
$query = "SELECT nom_ville,code_postal FROM ".$table_name." WHERE departement=%d";
$results = $wpdb->get_results( $wpdb->prepare($query, $code) );
$args = array();
foreach($results as $result):
$arg = array(
'posts_per_page' => 10,
'orderby' => 'post_date',
'order' => 'DESC',
'post_type' => 'ecole',
'post_status' => 'publish',
'meta_query' => array(
'relation' => 'AND',
array(
'key' => 'ecole_ville',
'value' => $result->nom_ville,
'compare' => '='
),
array(
'key' => 'ecole_post',
'value' => $result->code_postal,
'compare' => '='
)
)
);
$args[] = $arg;
endforeach;
var_dump($args); // Here shows so many items in $args
return($agrs);
}
$args = LBE_result_hompage_search_ecole_map();
var_dump($args); // Here shows NULL. I don't know why...
【问题讨论】:
-
你的函数中有
args和agrs -
非常感谢。我很抱歉,甚至不能原谅我这种低级的错误。我认为优秀的开发人员从小事做起。
标签: php arrays foreach null return