Created
December 4, 2018 17:43
-
-
Save toondaey/fc2143499f4857cc035a3deae14aae7a to your computer and use it in GitHub Desktop.
Solution to coding assignment
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 | |
include_once 'json.php'; | |
$people = json_decode($people, true); | |
$data = $people['data']; | |
$email = ''; | |
usort($data, 'compare'); | |
function compare ($prev, $next) { | |
if ($prev['age'] == $next['age']) { | |
return 0; | |
} | |
return ($prev['age'] > $next['age']) ? -1 : 1; | |
} | |
$data = array_map(function ($obj) use (&$email) { | |
$email .= "{$obj['email']},"; | |
$obj['name'] = "{$obj['first_name']} {$obj['last_name']}"; | |
return $obj; | |
}, $data); | |
$email = trim($email, ','); |
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 | |
$people = '{"data":[{"first_name":"jake","last_name":"bennett","age":31,"email":"[email protected]","secret":"VXNlIHRoaXMgc2VjcmV0IHBocmFzZSBzb21ld2hlcmUgaW4geW91ciBjb2RlJ3MgY29tbWVudHM="},{"first_name":"jordon","last_name":"brill","age":85,"email": "[email protected]","secret":"YWxidXF1ZXJxdWUuIHNub3JrZWwu"}]}'; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment