Skip to content

Instantly share code, notes, and snippets.

@sedera-tax
Created January 15, 2021 13:38
Show Gist options
  • Select an option

  • Save sedera-tax/7cc3cb992adc23d705bd359f2197111b to your computer and use it in GitHub Desktop.

Select an option

Save sedera-tax/7cc3cb992adc23d705bd359f2197111b to your computer and use it in GitHub Desktop.
1. File Owners Associative arrays Easy Implement a groupByOwners function that: Accepts an associative array containing the file owner name for each file name. Returns an associative array containing an array of file names for each owner name, in any order. For example, for associative array ["Input.txt" => "Randy", "Code.py" => "Stan", "Output…
<?php
function groupByOwners(array $files) : array
{
$res = [];
foreach($files as $key => $x)
{
$res[$x][] = $key;
}
return $res;
}
$files = array
(
"Input.txt" => "Randy",
"Code.py" => "Stan",
"Output.txt" => "Randy"
);
var_dump(groupByOwners($files));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment