Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

array of arrays 1

Status
Not open for further replies.

kurie

Programmer
Jun 4, 2008
170
ZA
hi all,
i have an array called $results; if i print its values(using print_r($results)) i get the values bellow.
My problem is i need to get the value of key, its an array within an array. Does anyone know what im supposed to do.
Array ( [AATSMS] => Array ( [0] => 0 [1] => 2 ) [SUBMITRESULT] => Array ( [0] => 1 ) ) Vals array Array ( [0] => Array ( [tag] => AATSMS [type] => open [level] => 1 ) [1] => Array ( [tag] => SUBMITRESULT [type] => complete [level] => 2 [attributes] => Array ( [ACTION] => enqueued [KEY] => 17730529 [RESULT] => 1 [NUMBER] => 888888888 ) ) [2] => Array ( [tag] => AATSMS [type] => close [level] => 1 ) )
regards
 
Its a multilevel array, you'll need to drill down into the arrays to get the array inside the "KEY" key . However, its hard to read in that form.

Try adding <pre> tags around your print_r so it can be read more easily, and post back the output.

Code:
echo "<pre>";
print_r($results);
echo "</pre>";






----------------------------------
Phil AKA Vacunita
----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
I think it should be something like this though I could be wrong:

$myarr["vals"]["attributes"]["KEY"]


----------------------------------
Phil AKA Vacunita
----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
thanks here is the result

array(3) {
[0]=>
array(3) {
["tag"]=>
string(6) "AATSMS"
["type"]=>
string(4) "open"
["level"]=>
int(1)
}
[1]=>
array(4) {
["tag"]=>
string(12) "SUBMITRESULT"
["type"]=>
string(8) "complete"
["level"]=>
int(2)
["attributes"]=>
array(4) {
["ACTION"]=>
string(8) "enqueued"
["KEY"]=>
string(8) "17731279"
["RESULT"]=>
string(1) "1"
["NUMBER"]=>
string(9) "888888888"
}
}
[2]=>
array(3) {
["tag"]=>
string(6) "AATSMS"
["type"]=>
string(5) "close"
["level"]=>
int(1)
}
}

Vals array
Array
(
[0] => Array
(
[tag] => AATSMS
[type] => open
[level] => 1
)

[1] => Array
(
[tag] => SUBMITRESULT
[type] => complete
[level] => 2
[attributes] => Array
(
[ACTION] => enqueued
[KEY] => 17731279
[RESULT] => 1
[NUMBER] => 888888888
)

)

[2] => Array
(
[tag] => AATSMS
[type] => close
[level] => 1
)

)
mykeyvalue=Arraymykeyvalue=Arraymykeyvalue=Array
 
O.k so yes, to access KEY its either $myarr["vals array"][1]["attributes"]["KEY"].

or $myresult[1]["attributes"]["KEY"]


should yield you the value of both KEY keys I see there.





----------------------------------
Phil AKA Vacunita
----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top