1

I am trying to access elements within an associative array. However, I do not seem to be able to get to the elements. If I use print_r() it says that is IS an array and shows me what is contained within it. However, is_array() returns false. Furthermore, when I echo the first element in the array it returns a value of 'a' rather than the actual array value. This is probably just some stupid mistake, but it is baffling me. Does anyone have any idea what the problem is here?

Thanks in advance for the help.

$sc2 = new ServiceCall($uri,null,false,false);
$sc2->makeCall();
$response = json_decode($sc2->getResponse(),true);
$tmp4 = var_export($response, true);
print_r($tmp4);
if(is_array($tmp4))
     echo "Tmp4 is an array";
else
     echo "Tmp4 is NOT an array";
11
  • 1
    What's the exact result of print_r($tmp4);? Commented Jul 11, 2012 at 16:08
  • Could you include the output of your print_r($tmp4)? Commented Jul 11, 2012 at 16:08
  • 5
    Must say: Sounds like you have a string "Array" ;) Commented Jul 11, 2012 at 16:09
  • Show us where and how you define $tmp4. Commented Jul 11, 2012 at 16:11
  • the result of print_r is: array ( 'RegStdClassLogService' => array ( 'request' => array ( 'method' => 'GET', 'resource' => '/583247982/20125/', ...etc... Commented Jul 11, 2012 at 16:11

1 Answer 1

2

var_export() is meant for persisting variables e.g. to files, thus it returns a string.

You can just use $response as your array, not $tmp4.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.