2013-04-28 62 views
0

我有一個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陣列,我總是收到此錯誤,並明確了,因爲我聲明它有一個在陣列中,絲毫不爲整數,無處。

對此錯誤的任何解決方案?

a http://imgbin.org/images/13129.png

+1

它顯然不是由於錯誤信息。var_dump或print_r你的「數組」,併發布結果 – 2013-04-28 01:26:45

+0

你應該只做'$ arr_foundits [] = $ it-> ID' ... – 2013-04-28 01:41:31

+1

這是一個基於文本的在線網站,請插入文本信息作爲文本 - 而不是截圖。這對於具體的錯誤消息很重要。 – hakre 2013-05-18 21:58:18

回答

4

array_push修改原始陣列,它不返回 「新」 之一。它返回數組的新長度,這是一個整數。所以第二次循環來臨時,你給它一個數字而不是數組。 Docs

+0

是的,offcouse,不知道如何逃脫我。 – digitalzoomstudio 2013-04-28 01:30:54

3

您正在覆蓋上的$arr_foundits。刪除$arr_foundits =,因爲array_push不返回數組,而是一個int。

+0

真的很奇怪。例如,array_merge返回一個數組,但是在語義上來自同一個字段的array_push返回一個int。反正, 謝謝! – digitalzoomstudio 2013-04-28 01:37:29

相關問題