dpwdldgn43486 2013-04-28 01:24
浏览 85
已采纳

array_push()期望参数1为数组[关闭]

I have a PHP problem.

I have this code block

$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));
            }
    }
}

The problem I am having is with the $arr_foundits array, I always receive this error, and clearly it's in array, no way an integer because I declare it there and nowhere else.

Any solution to this error ?

a
(source: imgbin.org)

  • 写回答

2条回答 默认 最新

  • dphs48626 2013-04-28 01:26
    关注

    array_push modifies the original array, it does not return the "new" one. It returns the new length of the array, which is an integer. so the second time the loop comes around you are feeding it a number instead of an array. Docs

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 求TYPCE母转母转接头24PIN线路板图
  • ¥100 国外网络搭建,有偿交流
  • ¥15 高价求中通快递查询接口
  • ¥15 解决一个加好友限制问题 或者有好的方案
  • ¥15 急matlab编程仿真二阶震荡系统
  • ¥20 TEC-9的数据通路实验
  • ¥15 ue5 .3之前好好的现在只要是激活关卡就会崩溃
  • ¥50 MATLAB实现圆柱体容器内球形颗粒堆积
  • ¥15 python如何将动态的多个子列表,拼接后进行集合的交集
  • ¥20 vitis-ai量化基于pytorch框架下的yolov5模型