Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

Howdie do,

I have one multidimensional associative array of server types. This array contains a sub array of values.

It's easier to see:

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

I want to add additional server type associative array. This is what I've done:

$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));

It does add the value, but it does it by index and not the actual server type key.

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 ) ) )

How do I move the sub arrays up one so that it adds them by key and not index. So that it looks like this

 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 ) ) )
share|improve this question
1  
$servers[SERVER_NAME] = array(WITH THE DATA IN IT) :) –  Darren Oct 8 '14 at 0:28
2  
just point it out to which server you want, just like that comment above ^ –  Ghost Oct 8 '14 at 0:32

1 Answer 1

up vote 2 down vote accepted

I'll just put it in an answer for you, because it is a simple typo.

Instead of creating an array object with an integer index ($server[] = array(....), what you want to do is this:

$servers['Atoms D510 1.66Ghz'] = array('Model' =>$AtomModel, 'Description' =>$AtomDesc,'Counter' => $AtomCount);
$servers['Celerons 2.40Ghz'] = array('Model' =>$CeleronModel, 'Description' =>$CeleronDesc,'Counter' => $CELERONCount);
share|improve this answer
    
Thank you sooooo much –  Jimmy Oct 8 '14 at 0:49

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.