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 2024-五一综合模拟赛
  • ¥15 下图接收小电路,谁知道原理
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭