Created
May 6, 2022 21:41
-
-
Save lukebouch/9b4584f9fd4d16497492bbd9d6e8bd37 to your computer and use it in GitHub Desktop.
This file contains 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
// Super Secret Spy Award | |
$people = '{"data":[{"first_name":"jake","last_name":"bennett","age":31,"email":"jake@bennett.com","secret":"VXNlIHRoaXMgc2VjcmV0IHBocmFzZSBzb21ld2hlcmUgaW4geW91ciBjb2RlJ3MgY29tbWVudHM="},{"first_name":"jordon","last_name":"brill","age":85,"email": "jordon@brill.com","secret":"YWxidXF1ZXJxdWUuIHNub3JrZWwu"},]}'; | |
$correctedJSON = preg_replace_callback("/(?:}(,)[^{])/", function($matches) { | |
return str_replace(",", "", $matches[0]); | |
} | |
, $people); | |
$data = collect(json_decode($correctedJSON)->data); | |
$emailAddresses = implode(', ', $data->map(function($person) { | |
return $person->email; | |
})->toArray()); | |
$newData = $data->each(function($person) { | |
return $person->name = $person->first_name . ' ' . $person->last_name; | |
})->sortByDesc('age'); | |
echo $emailAddresses, $newData; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment