<?php
$array = ["Ripe Mango"=>"Yellow", "Strawberry"=>"Red", "Lemon"=>"Yellow"];
var_export(
array_reduce(
array_keys($array),
fn($result, $key) => array_merge_recursive($result, [$array[$key] => [$key]]),
[]
)
);
- Output for 8.0.1 - 8.0.30, 8.1.0 - 8.1.33, 8.2.0 - 8.2.29, 8.3.0 - 8.3.26, 8.4.1 - 8.4.13
- array (
'Yellow' =>
array (
0 => 'Ripe Mango',
1 => 'Lemon',
),
'Red' =>
array (
0 => 'Strawberry',
),
)
preferences:
59.08 ms | 407 KiB | 5 Q