0

How can i enter this array and grab the orderId ?

array(1) { 

["data"] => array(1) {

["orderId"] => int(100)
  }

}

ive tried to

print_r ["array"]["1"]["array"]["1"]["orderId"];

ive tried

foreach($array as $data)
echo ["data"]["orderId"] ;

Also note, i am receiving this json as a webhook and decoding it to php object with json_decode($json, true);

What am i missing? Should be simple but i cannot get it.

Thanks

arrydavid
  • 123
  • 3
  • 8
  • what is the name of the variable containing the array? – Liora Haydont Jun 08 '18 at 21:15
  • Try this -> `$array[0]["data"][0]["orderId"]` – Vikas Jun 08 '18 at 21:18
  • @LioraHaydont, I guess the variable name is `$array`, as this variable is used in `foreach` loop. I am not sure whether this is a reserved keyword or not. – Vikas Jun 08 '18 at 21:20
  • 1
    I would recommend that you [read the manual about arrays](http://php.net/manual/en/language.types.array.php). It explains how you create arrays, read and set values. – M. Eriksson Jun 08 '18 at 21:26
  • a hint: the '1' you see here `array(1) { ` is _not_ the index, but the size (number of items in the array). And the 'array' is a description of the datatype, not a name. (because you tried `["array"]["1"]`). So `$array['data']['orderId']` would be it. – Jeff Jun 08 '18 at 21:37

3 Answers3

0

If your array is named $that, use $that['data']['orderId'];

davethegr8
  • 11,323
  • 5
  • 36
  • 61
0

Try this $array["data"]["orderId"] `

0

Assuming the JSON data you're receiving is in the $array variable:

$orderId = $array["data"]["orderId"];

Explanation:

  • First you grab the "data" property from the array

  • That data property contains another array which has its own properties.

  • From that array, you can grab the "orderId" property.

I hope this helps :)