How can json_encode() be used to simplify the output of a multidimensional array in PHP?

When dealing with a multidimensional array in PHP, the output can be complex and difficult to read. By using the json_encode() function, you can simplify the output by converting the multidimensional array into a JSON string. This makes it easier to read and work with the data.

$multiArray = array(
    'key1' => 'value1',
    'key2' => array(
        'subkey1' => 'subvalue1',
        'subkey2' => 'subvalue2'
    )
);

$jsonString = json_encode($multiArray);
echo $jsonString;