user3572565 user3572565 - 21 days ago 5
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

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];