array_push()期望参数1是数组
我有一个PHP问题。array_push()期望参数1是数组
我有这样的代码块
$arr_foundits = array();
foreach($its as $it){
//print_r($it);
$post_categories = wp_get_post_categories($it->ID);
$cats = array();
foreach($post_categories as $c){
$cat = get_category($c);
$catname = strtolower($cat->name);
//print_r($catname);
if($catname=='uncategorized'){
continue;
}
$squery = get_search_query();
if(strpos($catname, strtolower($squery))!==false){
//echo 'ceva';
$found = true;
$arr_foundits = array_push($arr_foundits, $it->ID);//line 80 hier
printf('<li><h4><a href="%1$s">%2$s</a></h4><p>%3$s</p></li>', get_permalink($it->ID), $it->post_title, get_the_excerpt_by_id($it->ID));
}
}
}
我遇到的问题是与$ arr_foundits阵列,我总是收到此错误,并明确了,因为我声明它有一个在阵列中,丝毫不为整数,无处。
对此错误的任何解决方案?
array_push
修改原始阵列,它不返回 “新” 之一。它返回数组的新长度,这是一个整数。所以第二次循环来临时,你给它一个数字而不是数组。 Docs
是的,offcouse,不知道如何逃脱我。 – digitalzoomstudio 2013-04-28 01:30:54
您正在覆盖上的$arr_foundits
。删除$arr_foundits =
,因为array_push
不返回数组,而是一个int。
真的很奇怪。例如,array_merge返回一个数组,但是在语义上来自同一个字段的array_push返回一个int。反正, 谢谢! – digitalzoomstudio 2013-04-28 01:37:29
它显然不是由于错误信息。var_dump或print_r你的“数组”,并发布结果 – 2013-04-28 01:26:45
你应该只做'$ arr_foundits [] = $ it-> ID' ... – 2013-04-28 01:41:31
这是一个基于文本的在线网站,请插入文本信息作为文本 - 而不是截图。这对于具体的错误消息很重要。 – hakre 2013-05-18 21:58:18