2013-06-28 18 views
0

你好我想,雖然推動循環和數組,並把它推到我的新陣列。我目前正在此錯誤..陣推,預計參數

array_push()預計參數1是數組,字符串

我不明白爲什麼這不工作,我的代碼看起來是這樣的。

$data['text'] = array(); 
    foreach($this->xml['paragraphs']['paragraph'] as $array) 
    { 
     array_push($array['text'], $data); 
    } 

我的陣列

[paragraphs] => Array 
    (
     [paragraph] => Array 
      (
       [0] => Array 
        (
         [text] => Solid wood door leading to entrance hallway, doors leading to Lounge/ Dining room and Shower room, double radiator, solid wood frame sash window to front, painted wood panell ceiling with single light, Indian slate floor. 
        ) 

       [1] => Array 
        (
         [text] => Solid wood frame sash window to front, double radiator, bathroom suite comrising: shower cubicle with obscure perspex panells, WC and vanity sink. Painted wood panel ceiling with single light. Heated towel rail, 
        ) 
+3

你混了'$ data'和'$ array'? – deceze

+1

爲什麼你避免這樣的簡單的解決方案:'$數據[] = $陣列[ '文本'];'? – Twisted1919

+0

無我不是混合起來IM彈到陣列 – Brent

回答

2
int array_push (array &$array , mixed $var [, mixed $... ]) 

array 
    The input array. 
var 
    The pushed value. 

它看起來對我來說,你已經顛倒了兩個參數。假設你遍歷$this->xml['paragraphs']['paragraph']並試圖推動各$array['test']結果中$data,它應該是這樣的:

array_push($data, $array['text']); 

// equivalent: 
// $data[] = $array['text']; 

不是相反。

+0

謝謝老兄:)我還在學習 – Brent

+0

@BrentFrench:不用擔心,大家都開始的地方。 ;-) –

相關問題