If I was you, I would parse the JSON as an array instead of as an object. This can be done by doing the following:

$json = json_decode($data, true);

By included the second argument in json_decode with a value of true, you get back an array. You can then do something like:

echo '<pre>';
print_r($json);
exit;

This will give you an idea of the array structure of the data and how to access the information you want. For example, to pull the title, brand, and description of each item, you'd do the following:

foreach($json['items'] as $item) {
    echo 'Title: ' . $item['product']['title'] . '<br />';
    echo 'Brand: ' . $item['product']['brand'] . '<br />';
    echo 'Description: ' . $item['product']['description'] . '<br />';
}

To get the availability, again do a dump of the array using print_r() and figure out the best way to access it from the array.

Answer from rahlstrom on Stack Overflow
๐ŸŒ
PHP
php.net โ€บ manual โ€บ en โ€บ function.json-decode.php
PHP: json_decode - Manual
You can cast it to an array or set the second parameter in the decode, but that assumes you were the one that encoded it and knew it was supposed to be an array. ... Browsers don't choke on integers _starting_ with BigInt (64 bits), but before that (53 bits). The introduction of BigInt to modern browsers doesn't help much, when JSON handling functions do not support it.
๐ŸŒ
W3Schools
w3schools.com โ€บ php โ€บ php_json.asp
PHP and JSON
PHP XML Parsers PHP SimpleXML Parser PHP SimpleXML - Get PHP XML Expat Parser PHP DOM Parser ยท AJAX Intro AJAX PHP AJAX Database AJAX XML AJAX Live Search AJAX Poll ยท PHP Examples PHP Compiler PHP Quiz PHP Exercises PHP Server PHP Syllabus PHP Study Plan PHP Certificate ... array() array_change_key_case() array_chunk() array_column() array_combine() array_count_values() array_diff() array_diff_assoc() array_diff_key() array_diff_uassoc() array_diff_ukey() array_fill() array_fill_keys() array_filter() array_flip() array_intersect() array_intersect_assoc() array_intersect_key() array_intersect
๐ŸŒ
CodeSignal
codesignal.com โ€บ learn โ€บ courses โ€บ handling-json-files-with-php โ€บ lessons โ€บ parsing-json-arrays-with-php
Parsing JSON Arrays with PHP
Welcome to this lesson on parsing arrays within JSON structures using PHP. As you've learned in previous lessons, JSON (JavaScript Object Notation) is a popular data format used for exchanging data due to its simplicity and readability. JSON arrays are crucial for representing collections of ...
๐ŸŒ
Reddit
reddit.com โ€บ r/phphelp โ€บ help parsing json array using php
r/PHPhelp on Reddit: Help parsing JSON array using PHP
April 20, 2022 -

I have figured out half of what I am trying to do here.

I have a JSON array that is being returned via API. I am wanting to parse that array and pull out just the Unique ID and Email Address for each user.

Each user has a key called 'unique_id' regardless of whether or not it is defined. Each user only has a key called 'email' if a user in fact has an email address defined.

Sample Code:

 foreach ($arr["data"]["users"] as $value) {
   echo $value["unique_id"];
   echo $value["email"]; 
}

This code works....sort of. This will output the unique_id for each user. If there is no value defined, it simply returns a blank value. Cool. However, for the key email, I get an error: Undefined array key "email".

Am I getting this because not every user has this key?

You can see a sample of the array output here: https://pastebin.com/9D4mWyKL

๐ŸŒ
ReqBin
reqbin.com โ€บ code โ€บ php โ€บ 0uwqq41y โ€บ json-to-array-php-example
How do I convert JSON to PHP array?
To convert a JSON data string to a PHP array, you can use the json_decode($json) function. The json_decode() function accepts the JSON string as the first parameter and a few additional parameters to control the process of converting JSON to ...
๐ŸŒ
TutorialsPoint
tutorialspoint.com โ€บ parsing-json-array-with-php-foreach
Parsing JSON array with PHP foreach
<?php $json_array ='{ "values": { "a": "abc", "d": 0, "efg": 349 } }'; $array = json_decode($json_array, true); foreach($array as $values) { echo $values['efg']; echo $values['d']; echo $values['a']; }
๐ŸŒ
Tutorial Republic
tutorialrepublic.com โ€บ php-tutorial โ€บ php-json-parsing.php
How to Encode and Decode JSON Data in PHP - Tutorial Republic
In PHP the json_encode() function is used to encode a value to JSON format. The value being encoded can be any PHP data type except a resource, like a database or file handle. The below example demonstrates how to encode a PHP associative array ...
Find elsewhere
๐ŸŒ
Envato Tuts+
code.tutsplus.com โ€บ home โ€บ cloud & hosting
How to Parse JSON in PHP | Envato Tuts+
May 31, 2021 - This tutorial will teach you how to read a JSON file and convert it to an array in PHP. Learn how to parse JSON using the json_decode() and json_encode() functions.
๐ŸŒ
W3Schools
w3schools.com โ€บ js โ€บ js_json_php.asp
JSON PHP
Here is a JavaScript on the client, using an AJAX call to request the PHP file from the array example above: Use JSON.parse() to convert the result into a JavaScript array:
๐ŸŒ
W3Docs
w3docs.com โ€บ php
How to Create and Parse JSON Data with PHP
<?php // An indexed array $colors ... a non-associative one- both as an object and an array. For parsing a JSON data you can use decoding....
๐ŸŒ
PHP: json_decode()
parthpatel.net โ€บ home โ€บ php โ€บ php: json_decode() | how to decode json to array in php
PHP: json_decode() | How to decode json to array in PHP | Parth Patel - a Web Developer
September 9, 2021 - <?php // Store JSON data in a PHP variable $json = '{"email":"john@doe.com"}'; $obj = json_decode($json); print $obj->email; ?> ... Here's the simple explanation to how json_encode() works and how you can parse json to array or class objects in PHP.
๐ŸŒ
Jonathan Suh
jonsuh.com โ€บ blog โ€บ convert-loop-through-json-php-javascript-arrays-objects
Convert and Loop through JSON with PHP and JavaScript Arrays/Objects โ€” Jonathan Suh
PHP >= 5.2.0 features a function, json_decode, that decodes a JSON string into a PHP variable. By default it returns an object. The second parameter accepts a boolean that when set as true, tells it to return the objects as associative arrays.
๐ŸŒ
ReqBin
reqbin.com โ€บ code โ€บ php โ€บ ozcpn0mv โ€บ php-parse-json-example
How do I parse JSON string in PHP?
To parse a JSON string to a PHP object or array, you can use the json_decode($json) function. The json_decode() function recursively converts the passed JSON string into the corresponding PHP objects.
๐ŸŒ
SourceBae
sourcebae.com โ€บ home โ€บ how to get values of json array elements in php
How to Get Values of JSON Array Elements in PHP - SourceBae
August 21, 2025 - Now, letโ€™s delve into the practical aspects of extracting data from a JSON array in PHP. The json_decode function in PHP is your go-to tool for parsing JSON data.
๐ŸŒ
CodeSignal
codesignal.com โ€บ learn โ€บ courses โ€บ handling-json-files-with-php โ€บ lessons โ€บ parsing-and-accessing-json-data-with-php
Parsing and Accessing JSON Data with PHP
Decode the data using json_decode() to convert it into a PHP associative array. ... To access specific data from the parsed JSON, such as the school name, you navigate the hierarchical structure using keys:
๐ŸŒ
Nidup
nidup.io โ€บ blog โ€บ manipulate-json-files-in-php
Read, Decode, Encode, Write JSON in PHP | Nicolas Dupont
March 12, 2022 - We use json_decode to convert (decode) the string to a PHP associative array.