collect file name with owner name in array code example
Example: collect file name with owner name in array
<?php
function groupByOwners(array $files) : array
{
$newArray = array();
foreach($files as $key=>$f){
$newArray[$f][] = $key;
}
return $newArray;
}
$files = array
(
"Input.txt" => "Randy",
"Code.py" => "Stan",
"Output.txt" => "Randy"
);
print_r(groupByOwners($files));
?>
Given the Array:
["Input.txt" => "Randy", "Code.py" => "Stan", "Output.txt" => "Randy"]
Expected Returns:
["Randy" => ["Input.txt", "Output.txt"], "Stan" => ["Code.py"]]