Skip to content

Instantly share code, notes, and snippets.

@srph
Created April 1, 2019 13:03
Show Gist options
  • Save srph/71f145954e67e671cd36bb45bafa5f4d to your computer and use it in GitHub Desktop.
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
<?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