How can PHP array functions be utilized to manipulate nested arrays for cosmetic purposes?

When working with nested arrays in PHP, array functions can be used to manipulate the structure of the arrays for cosmetic purposes. This can include reordering elements, adding or removing elements, or restructuring the array to make it easier to work with.

// Example of using array functions to manipulate a nested array for cosmetic purposes

// Original nested array
$nestedArray = [
    'fruit' => [
        'apple' => 'red',
        'banana' => 'yellow'
    ],
    'vegetable' => [
        'carrot' => 'orange',
        'lettuce' => 'green'
    ]
];

// Reordering the elements within the 'fruit' array
$nestedArray['fruit'] = array_reverse($nestedArray['fruit']);

// Adding a new element to the 'fruit' array
$nestedArray['fruit']['orange'] = 'orange';

// Restructuring the array to have a 'produce' key containing both 'fruit' and 'vegetable' arrays
$nestedArray['produce'] = $nestedArray;
unset($nestedArray['fruit']);
unset($nestedArray['vegetable']);

print_r($nestedArray);