Single associative array value grouping based on key

Links for php scripts

Moderators: egami, macek, gesf

Post Reply
New php-forum User
New php-forum User
Posts: 1
Joined: Fri Oct 27, 2017 12:30 pm

Fri Oct 27, 2017 12:43 pm ... tion/11840 I can`t complete this easy test :( .

I can`t figure out how to complete this one. I went so below so far.

class FileOwners
public static function groupByOwners($files)
$grouped = array();
foreach ($files as $value => $key){
$grouped[$key][$value] = $key;
//print "$key = $val\n";

return $grouped;


$files = array
"Input.txt" => "Randy",
"" => "Stan",
"Output.txt" => "Randy"

Can anyone show me how to do it? Thanks!

User avatar
php-forum Fan User
php-forum Fan User
Posts: 839
Joined: Mon Feb 22, 2016 5:52 pm

Sat Oct 28, 2017 2:12 am

It would help if you explained what you are having problems with, don't provide links to problems which you have to solve on your own, we can help but will not do it for you.

What is the script doing, and what errors you are getting.

Post code using the </> code button.

And it should be:

Code: Select all

foreach ($myarray as $key => $value)

Post Reply