2011-11-03 44 views
0

我試圖數組變量的一部分設置到一個新的數組變量,如下面的部分設置數組變量:試圖從另一個數組變量

$this->data['uploadFront'] = array(); 
$this->data['uploadFront'] = $this->data['Card']['uploadFront']; 

但是我卻越來越不確定的指數錯誤。

的$這個 - >數據[「卡」]數組是象下面這樣:

Array 
(
    [Card] => Array 
     (
      [name] => 
      [company_name] => 
      [firstname] => 
      [lastname] => 
      [position] => 
      [location] => 
      [phone] => 
      [website] => 
      [mobile] => 
      [comp_name] => 0 
      [uploadFront] => Array 
       (
        [name] => 
        [type] => 
        [tmp_name] => 
        [error] => 4 
        [size] => 0 
       ) 

      [uploadBack] => Array 
       (
        [name] => 
        [type] => 
        [tmp_name] => 
        [error] => 4 
        [size] => 0 
       ) 

     ) 

) 

出了什麼問題,需要加以固定在這個過程嗎?

+0

其中索引是不確定的? – Catalin

+0

如果您說「$ this-> data ['Card']數組如下所示:」及以下,第一個鍵是'Card',並且您嘗試訪問您的行中的'uploadFront'...所以幾乎你在說什麼,你應該有:'$ this-> data ['uploadFront'] = $ this-> data ['Card'] ['Card'] ['uploadFront'];' – Catalin

+0

告訴我們,你怎麼樣將$ this-> data變量傳遞給你的方法?我的意思是,你問php什麼?事實上,如果你告訴我們$ this-> data ['Card']數組是你正在使用的數組,而不是$ this-> data數組,那麼你沒有索引,因爲你試圖訪問數組實際上正在努力。 – NikM

回答

0
$this->data['uploadFront'][] = $this->data['Card']['uploadFront']; 

如果要追加到數組,你必須使用[]表明要附加,不assinging。

+0

對不起,我試過,但我得到同樣的錯誤。這用於php類。 –

0

對不起,我第一次沒有閱讀您的帖子。正如Catalin告訴你的,如果你的數組是你所告訴我們的,例如$ this-> data ['Card'] = ARRAY,那麼你創建了一個不必要的額外級別:兩次'Card',所以[''卡 '] [' 卡'。我建議你定義$ this-> data,就像你所說的是你的數組,然後要求將''uploadFront''複製到$ this-> data數組的第一層。在你描述的內容中,你試圖訪問數組中未被佔用的部分。

在代碼中(可能是你需要在你的類別的地方申報$這個 - >數據陣列,但解釋的緣故,我把它寫下來是這樣):

$this->data = array 
(
'Card' => array 
    (
     'name' => '', 
     'company_name' => '', 
     ... 
     'uploadFront' => array 
      (
       'name' =>'', 
       'type' => '', 
       'tmp_name' => '', 
       'error' => '4', 
       'size' => '0' 
      ) 

     'uploadBack' => array 
      (
       ... 
      ) 

    ) 

$this->data['uploadFront'] = $this->data['Card']['uploadFront']; 
相關問題