Created
January 15, 2021 13:38
-
-
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…
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?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