array:5 [▼
"cool" => array:4 [▼
0 => "c"
1 => "o"
2 => "o"
3 => "l"
]
"looc" => array:4 [▼
0 => "l"
1 => "o"
2 => "o"
3 => "c"
]
"test" => array:4 [▼
0 => "t"
1 => "e"
2 => "s"
3 => "t"
]
"set" => array:3 [▼
0 => "s"
1 => "e"
2 => "t"
]
"get" => array:3 [▼
0 => "g"
1 => "e"
2 => "t"
]
]
[
[
'cool',
'looc'
], [
'test'
], [
'set'
], [
'get'
],
]
"cloo"
два значения ["cool", "looc"]
, а для остальных по одному.<?php
$data = [
"cool" => [0 => "c", 1 => "o", 2 => "o", 3 => "l"],
"looc" => [0 => "l", 1 => "o", 2 => "o", 3 => "c"],
"test" => [0 => "t", 1 => "e", 2 => "s", 3 => "t"],
"set" => [0 => "s", 1 => "e", 2 => "t"],
"get" => [0 => "g", 1 => "e", 2 => "t"]
];
$groups = [];
foreach( $data AS $k => $v) {
sort($v);
$hash = implode('', $v);
if(!isset($groups[$hash])) $groups[$hash] = [];
array_push($groups[$hash], $k);
}
$result = array_values($groups);
print_r($result);
/*
Array(
[0] => Array
(
[0] => cool
[1] => looc
)
[1] => Array
(
[0] => test
)
[2] => Array
(
[0] => set
)
[3] => Array
(
[0] => get
)
)
*/