2014-10-08 32 views
0

Howdie do,在2x2多維數組中添加額外的關聯數組但是存儲密鑰

我有一個服務器類型的多維關聯數組。該數組包含值的子數組。

很容易地看到:

$servers = array('Dell R410 Dual Xeon X5650 Hexacore 2.66 GHz' => array('Model' =>$R410Model, 'Description' =>$R410Desc,'Counter' => $R410HexCoreE5650Count)); 

我要添加額外的服務器類型關聯數組。這是我做了什麼:

$servers[] = array('Atoms D510 1.66Ghz' => array('Model' =>$AtomModel, 'Description' =>$AtomDesc,'Counter' => $AtomCount)); 

$servers[] = array('Celerons 2.40Ghz' => array('Model' =>$CeleronModel, 'Description' =>$CeleronDesc,'Counter' => $CELERONCount)); 

它確實增加了價值,但它的指標,而不是實際的服務器類型鍵做的。

Array ([Dell R410 Dual Xeon X5650 Hexacore 2.66 GHz] => Array ([Model] => DELL R410 [Description] => Dual Xeon X5650 Hexacore 2.66 GHz [Counter] => 25) 

[0] => Array ([Atoms D510 1.66Ghz] => Array ([Model] => ATOM [Description] => D510 1.66Ghz [Counter] => 1)) 

[1] => Array ([Celerons 2.40Ghz] => Array ([Model] => [Description] => [Counter] => 0))) 

如何移動的子陣列了一個使之通過鍵,而不是指數增加了他們。因此,它看起來像這樣

Array ([Dell R410 Dual Xeon X5650 Hexacore 2.66 GHz] => Array ([Model] => DELL R410 [Description] => Dual Xeon X5650 Hexacore 2.66 GHz [Counter] => 25) 

Array ([Atoms D510 1.66Ghz] => Array ([Model] => ATOM [Description] => D510 1.66Ghz [Counter] => 1)) 

Array ([Celerons 2.40Ghz] => Array ([Model] => [Description] => [Counter] => 0))) 
+1

'$服務器[SERVER_NAME] =陣列(在IT數據)':) – Darren 2014-10-08 00:28:09

+2

只是指出了你想要的服務器,就像上面的評論^ – Ghost 2014-10-08 00:32:24

回答

2

我只是把它放在你的答案,因爲它是一個簡單的錯字。

而是與一個整數值($server[] = array(....)創建一個數組對象,你想做的事是這樣的:

$servers['Atoms D510 1.66Ghz'] = array('Model' =>$AtomModel, 'Description' =>$AtomDesc,'Counter' => $AtomCount); 
$servers['Celerons 2.40Ghz'] = array('Model' =>$CeleronModel, 'Description' =>$CeleronDesc,'Counter' => $CELERONCount); 
+0

謝謝sooooo much – Jimmy 2014-10-08 00:49:15