$arr1 = array('a' => '1', 'b' => 'blah', 'c' => 'whatever...',
'aa' => '2', 'bb' => 'lbha', 'cc' => 'everwhat...', 'dd' => 'bingo',
'aaa' => '3', 'bbb' => 'halb', 'ccc' => 'revetahw...');
In the array, I have three different index lengths a, b and c - all 1 in length. aa, bb, cc and dd have a length of 2. And aaa, bbb and ccc have a length of 3.
I am trying to find the index (group by length) with the most elements and the longest.
so I would use aa, bb, cc, dd, since they have 4 elements, this will return the length of index 2.
I want to know how can I get 2?
Here is what I am trying but not working
foreach($arr1 as $key => $data) {
$index_length_arr[strlen($key)] = $index_length_arr[$key] + 1;
}
Results:
Array
(
[1] => 1
[2] => 1
[3] => 1
)
Expected Result:
Array
(
[1] => 3
[2] => 4
[3] => 3
)
Then I could see that the index (with a length of 2) had the largest number of elements:
'aa' => '2', 'bb' => 'lbha', 'cc' => 'everwhat...', 'dd' => 'bingo',