No announcement yet.

[RESOLVED] Need help with an array issue

  • Filter
  • Time
  • Show
Clear All
new posts

  • [RESOLVED] Need help with an array issue

    So, I have a JSON object that I am casting to an array with json_decode. The thing is the array is multi-layered, but not as a multi-dimensional array would be... Here is an example though this is still in object format.

    object(stdClass)#2916 (15) {
        string(12) "34563"
        string(3) "My Other Site"
        string(1) "0"
        string(1) "0"
        string(3) "244"
        string(1) "N"
        string(10) "0000-00-00"
        string(0) ""
        string(1) "0"
        string(1) "0"
        string(1) "N"
        string(3) "out"
        string(25) "Another Customer"
        array(1) {
          object(stdClass)#2830 (7) {
            string(12) "34563"
            string(6) "34578"
            string(10) "2015-06-08"
            string(6) "wwweee"
            string(12) "Another City"
            string(3) "RRR"
            string(31) "DO NOT SHIP BEFORE 6/8
    $  769P"
    Note how the detail row is its own array. I need to access a value from the ordnbr field which is under detail. I have tried everything I know including trying to access it as if it were a multi-dimensional array $myArray['detail']['ordnbr']
    Nothing I have tried works. Can someone please point me in the right direction.
    Thanks in advance.

  • #2
    json_decode() returns an object, not an array. You would access it like this:
    PHP Code:
    If you want an array instead, pass TRUE as the second parameter for json_decode() like so:
    PHP Code:
    $myArray json_decode$theJSONTRUE ); 
    Then you can access like so:
    PHP Code:
    json_decode() Specifications


    • #3
      Thank you ScareCrowe... I should have known that. I think I had just gotten so aggravated with this that I couldn't think it through clearly...