Accessing data from an array that has an INT before it begins

Viewed 22

I'm pulling data from an API. It comes through as follows:

    int(621)
    array(3) {
        ["self"]=>array(1) {["href"]=>string(28) "/inventory?pgsiz=100&pgnum=1"
      }
        ["next"]=>array(1) {["href"]=>string(28) "/inventory?pgsiz=100&pgnum=2"
      }
        ["item"]=>array(1) {["href"]=>string(0) ""
      }
    }
    array(1) {
        ["item"]=>
      array(100) {
        [0]=>
        array(25) {
          ["receiverId"]=>int(1623456)
          ["receivedDate"]=>string(22) "2020-07-27T07:37:43.73"
          ["receiveItemId"]=>int(132576)
          ["customerIdentifier"]=>array(2) { ...

Everything I do to try to access the data in array(100) fails. I think it's because I'm trying to navigate like it's a multidimensional array, but in reality, the first item in this data isn't an array at all, it's an INT.

How can I skip the int(621) as well as the array(3) and access item?

Edit (print_r)::

Array
(
    [totalResults] => 621
    [_links] => Array
        (
            [self] => Array
                (
                    [href] => /inventory?pgsiz=1000&pgnum=1
                )

            [item] => Array
                (
                    [href] => 
                )

        )

    [_embedded] => Array
        (
            [item] => Array
                (
                    [0] => Array
                        (
                            [receiverId] => 1623456
                            [receivedDate] => 2020-07-27T07:37:43.73
                            [receiveItemId] => 1623456
                            [customerIdentifier] => Array ...
1 Answers

I assume you want to look at all 100 occurances, so something like this would get you started

foreach( $arr['__embedded']['item'] as $occ ) {
    echo $occ['receiverId'];
}

Watch out as [customerIdentifier] appears to also be another array, but you have not shown what happens after that so its all yours to explore

Related