How can JSON data be sorted and accessed based on specific keys in PHP?

To sort and access JSON data based on specific keys in PHP, you can decode the JSON string into an associative array using `json_decode()`, then use functions like `array_multisort()` or `usort()` to sort the data based on the specific key. You can then access the sorted data using the keys as you would with any associative array.

// Sample JSON data
$jsonData = '{"users":[{"name":"Alice","age":30},{"name":"Bob","age":25},{"name":"Charlie","age":35}]}';

// Decode JSON data into an associative array
$data = json_decode($jsonData, true);

// Sort data based on the 'age' key
usort($data['users'], function($a, $b) {
    return $a['age'] - $b['age'];
});

// Access sorted data
foreach ($data['users'] as $user) {
    echo $user['name'] . ' - ' . $user['age'] . PHP_EOL;
}