Joshi
Joshi

Reputation: 2790

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

Upvotes: 0

Views: 51

Answers (2)

Translations Cloud
Translations Cloud

Reputation: 53

the structure is an array, inside of an object, so this should work (but you need to give a name to your array (for example "matthew"):

matthew->sambalpur25.com["status"] or matthew.sambalpur25.com["status"]

Upvotes: 0

Graeme
Graeme

Reputation: 124

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.

Upvotes: 3

Related Questions