Created
April 1, 2019 13:03
-
-
Save srph/71f145954e67e671cd36bb45bafa5f4d to your computer and use it in GitHub Desktop.
Converts an array of objects into an object, keys based on its key
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 | |
namespace App\Support; | |
class Helper { | |
/** | |
* Converts an array of objects into an object, keys based on its key | |
* [{ "entry_date": "" }, { "entry_date": "" }] -> { "2019-08-20": {}, ... } | |
*/ | |
static public function toPropertyKeys($array, $property) { | |
$result = []; | |
foreach ($array as $item) { | |
$result[$item[$property]] = $item; | |
} | |
return $result; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment