What are best practices for handling multi-dimensional arrays in PHP when working with JSON data?

When working with multi-dimensional arrays in PHP and encoding them to JSON data, it is important to properly structure the arrays to ensure the JSON output is correctly formatted. One best practice is to use associative arrays to represent nested data structures. This can be achieved by nesting arrays within arrays or using key-value pairs to represent nested objects.

// Example of handling multi-dimensional arrays in PHP when working with JSON data

// Create a multi-dimensional array
$data = array(
    'name' => 'John Doe',
    'age' => 30,
    'address' => array(
        'street' => '123 Main St',
        'city' => 'Anytown',
        'state' => 'CA'
    )
);

// Encode the array to JSON
$json_data = json_encode($data);

// Output the JSON data
echo $json_data;