What are the potential issues when trying to extract data from a JSON array in PHP?

One potential issue when extracting data from a JSON array in PHP is that the data may be nested within multiple levels of arrays and objects, making it difficult to access the desired information. To solve this, you can use a combination of array indexing and object properties to navigate through the JSON structure and extract the data you need.

// Sample JSON data
$jsonData = '{
    "users": [
        {
            "id": 1,
            "name": "John Doe",
            "email": "john.doe@example.com"
        },
        {
            "id": 2,
            "name": "Jane Smith",
            "email": "jane.smith@example.com"
        }
    ]
}';

// Decode JSON data
$data = json_decode($jsonData, true);

// Accessing the name of the first user
$firstName = $data['users'][0]['name'];
echo $firstName; // Output: John Doe