user3572565 user3572565 - 1 year ago 79
PHP Question

Getting a value from a php array using the index number

I have an array called $alldata

If I do this

echo $alldata[0][6][0]["COLOUR"];

It successfully returns the colour. I want to access the value without using the name / label "COLOUR"

I tried this, but it fails with undefined offset
echo $alldata[0][6][0][0];

Answer Source

Re-index so you can use a numeric index:

echo array_values($alldata[0][6][0])[0];

Or for them all:

$result = array_values($alldata[0][6][0]);
echo $result[0];
echo $result[2];
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download