Joshi Joshi - 1 month ago 15
PHP Question

Accessing Mulit-dimensional non indexed array

I am getting this array with a

var_dump($data);


array (size=1)
'sambalpur25.com' =>
array (size=2)
'classkey' => string 'domcno' (length=6)
'status' => string 'available' (length=9)


Now I want to access the value of
status
from the array, I have tried it multiple ways, but couldn't get the result.

I have attempted like below without any success;

var_dump($data[0]['status']);exit;
var_dump($data['status']);exit;


foreach($data as $key => $val){
echo $data[$key];
}

Answer
foreach($data as $key => $val){
    $classkey = $val['classkey'];
    $status = $val['status'];
}

You were close, in this case $key is 'sambalpur25.com' and $val is the array at that index. If you're fine to iterate over it like that, then use $val.