Not getting value from array

I have this array called $res

    [result_data] => 11
    [status] => success
    [message] => Total record
    [status_code] => 200

How do I get the value of [result_data]

echo $res->result_data;

isn’t working


-> is to get object properties. Arrays use brackets. $res[‘result_data’]

$res[‘result_data’] doesn’t work either

echo $res[‘result_data’]; is coming out as <


foreach ($res as $key) {   
    echo "$key";
   echo "hH";

echo "fff";

$total_records = $res['total_records'];

is the code

This is what I am getting

[result_data] => 11
[status] => success
[message] => Total record
[status_code] => 200

Warning: Invalid argument supplied for foreach() in

Warning: Illegal string offset ‘total_records’ in

It doesn’t make sense

This worked for me, though I do not know if it will suite you.

$myArray = array(
“result_data” => ‘11’,
“status” => ‘success’,
“message” => ‘Total record’,
“status_code” => ‘200’,

echo $myArray[‘result_data’];

Prints: 11

and are you wanting to echo out “$key” or are you wanting to print_r($key)?

I found the problem eventually - it was thinking the array was a string not an array because of a previous syntex error.

Sponsor our Newsletter | Privacy Policy | Terms of Service