What is the best way to handle multidimensional arrays from a text file in PHP?

When handling multidimensional arrays from a text file in PHP, one efficient way is to use the `json_encode` and `json_decode` functions to convert the array to a JSON string and vice versa. This allows for easy storage and retrieval of complex data structures from text files.

// Read data from text file
$data = file_get_contents('data.txt');

// Convert JSON string to multidimensional array
$array = json_decode($data, true);

// Access the multidimensional array
echo $array['key1']['key2'];

// Modify the multidimensional array
$array['key1']['key2'] = 'new value';

// Convert array back to JSON string and save to text file
file_put_contents('data.txt', json_encode($array));