Single associative array value grouping based on key

A

Anonymous

Guest
https://www.testdome.com/for-developers/solve-question/11840 I can`t complete this easy test :( .

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

<?php
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",
"Code.py" => "Stan",
"Output.txt" => "Randy"
);
var_dump(FileOwners::groupByOwners($files));
?>

Can anyone show me how to do it? Thanks!
 
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:
foreach ($myarray as $key => $value)
 
Back
Top