2013-01-05 99 views
-1

我有以下文件,其中包含下一個代碼,我試圖通過將它們添加到數組來跟蹤一些項目。array_push()和in_array()無法弄清楚

header('Content-type: application/json'); 
$json_output = array(); 
$json_parcurs = array(); 
function generate_json_file($depth, &$json_output, $parent_id, &$children = null, $child_nr = null , $percentage = 0,$id_child = null,$type = 0,&$json_parcurs){ 


[code]..... 


for($i=0; $i<$nr_of_children; $i++) 
      { 
       if (!in_array($firma[$i+1]['vessta_id'],$json_parcurs)) 
        // Run recurence function 
        if ($firma[$i+1]['shareholder_id'] != '') 
        { 
         array_push($json_parcurs,$firma[$i+1]['vessta_id']); 
         generate_json_file($depth, $json_output, $table_init[1][0], $json_output['children'], $i,$firma[$i+1]['percentage_held'],$firma[$i+1]['vessta_id'],0,$json_parcurs); 
        }      
      } 

} 
generate_json_file(0, $json_output, 0); 

echo json_encode($json_output); 

我的問題是,我得到了很多的警告,像這樣:

[05-Jan-2013 22:49:24 UTC] PHP Warning: in_array() expects parameter 2 to be array, null given in 
[05-Jan-2013 22:49:24 UTC] PHP Warning: array_push() expects parameter 1 to be array, null given 
+0

'$ json_parcurs'不具有價值,請檢查一下。 – devOp

回答

0

您正在使用錯誤的方法函數默認參數。你總是必須指定默認值。

嘗試定義你這樣的功能 -

function generate_json_file(... $type = 0,$json_parcurs = &$json_parcurs){ 
... 
} 
+0

語法錯誤... –

+0

@sta - 爲了這個答案,我縮短了參數列表..你剛剛複製並粘貼它嗎? – Lix

+0

我知道,但$ json_parcurs =&$ json_parcurs是一個語法錯誤。 –