2014-10-08 26 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