Jump to content

StevenOliver

Members
  • Posts

    237
  • Joined

  • Last visited

  • Days Won

    6

Everything posted by StevenOliver

  1. What is confusing me is it is currently working with What is confusing me is that this is working with "json_decode": $result = json_decode($result,true); echo $result["fromAddress"]["phone"]; But changing it to "json_encode" causes it to fail: the $result["fromAddress"]["phone"] part will not work. (I wish I could just say "yeah it's working I'll leave it alone"..... but I always have to know "why") :-)
  2. I thought I'd try one last thing, and of course, it works: $result = json_decode($result,true); echo $result["fromAddress"]["phone"]; But even though this works, I am still wondering why I cannot access the "phone" variable using Object Style: echo $result->fromAddress->phone;
  3. I use a CURL script API with the header "$headers[] = 'Content-Type: application/json';" The script ends with "$result = curl_exec($ch);" If I simply echo the $result to my browser, I get an array that looks like this: stdClass Object ( [fromAddress] => stdClass Object ( [name] => Fred Sender [phone] => 203-111-0000 ) [toAddress] => stdClass Object ( [name] => Susan Recipient [phone] => 919-555-1212 What is the absolute minimum I need to do to access the phone number in the "toAddress" (919-555-1212). Do I really need to "json_decode" this array? I've spent 2 1/2 days trying every which way, with every permutation to access that one value: echo $result["fromAddress"]["phone"]; echo $result->fromAddress->phone; echo $result[0]->fromAddress->phone echo $arr[0]->fromAddress->phone; // $arr = json_decode($result); echo $arr->fromAddress->phone; echo $arr[0]->fromAddress->phone; echo $arr[0]->fromAddress["phone"]; Unfortunately I must have fallen asleep during the array lesson in PHP class ? Thank you.
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.