-2

I have a variable, $result, that hold the following:

object(stdClass) #1 (1) { ["response"]= > object(stdClass) #2 (6) { 
["status"]= > string(2) "OK" 
["count"] => int(1)
["flash_click_variable"] => NULL
["no_iframes"] => bool(false)
["content1"] => string(765)
"document.write('\r\n\r\n');" 
["content2"] => string(711)
"<strong>hello world</strong>
" ["
file_name "]=> NULL ["
track_clicks "]=> bool(true) ["
audit_status "]=> string(7) "
audited " ["
macros "]=> string(12) "
ADV_ID, CP_ID " ["
profile_id "]=> NULL ["
audit_feedback "]=> string(0) "
"

If I var_dump the variable, "hello world" is rendered (because of document.write) in bold...among other elements in the array.

I want to only var dump content1 in the array.

I know I should be using -> but how do I do this when there are multiple object(stdClass).

I only want the 1st record in the array.

I tried echo $result[0]->response[count]; just to see if I could pull out the count value but it wasn't giving anything before trying to echo content1. How do I do this?

Cody Raspien
  • 1,753
  • 5
  • 26
  • 51

2 Answers2

1

can you please write the whole code, that seams to be a MYSQL Object right?

You can read this: php stdClass to array

Or try to convert.

Converting an array/stdClass -> stdClass

$stdClass = json_decode(json_encode($Result));

Or convert to an array $array = json_decode(json_encode($Result), true);

echo $Result["response"]["content1"];

Hope this helps.

Ohh just iterate over the object to find out what it prints. If it prints all in one foreach loop then you can use this to index other elements.

Or Try this:

echo extract( $results->out->transactions->RealTimeCommissionDataV2, EXTR_PREFIX_ALL, 'websiteId' );

// test the extract
print_r( $websiteId_0 );
Community
  • 1
  • 1
IsoFunCode
  • 57
  • 7
1

The proper syntax is:

echo $result[0]->response->count

so

echo $result[0]->response->content1
Ibu
  • 42,752
  • 13
  • 76
  • 103