0

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 ) ) )
2
  • 1
    $servers[SERVER_NAME] = array(WITH THE DATA IN IT) :) Commented Oct 8, 2014 at 0:28
  • 2
    just point it out to which server you want, just like that comment above ^ Commented Oct 8, 2014 at 0:32

1 Answer 1

2

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);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.