You are here

function entity_key_array_by_property in Entity API 7

Converts an array of entities to be keyed by the values of a given property.

Parameters

array $entities: The array of entities to convert.

$property: The name of entity property, by which the array should be keyed. To get reasonable results, the property has to have unique values.

Return value

array The same entities in the same order, but keyed by their $property values.

6 calls to entity_key_array_by_property()
EntityAPIController::view in includes/entity.controller.inc
Implements EntityAPIControllerInterface.
EntityAPIControllerExportable::attachLoad in includes/entity.controller.inc
Overridden.
EntityAPIControllerExportable::cacheSet in includes/entity.controller.inc
Overridden.
EntityAPIControllerExportable::load in includes/entity.controller.inc
Overridden to support passing numeric ids as well as names as $ids.
entity_load_multiple_by_name in ./entity.module
A wrapper around entity_load() to return entities keyed by name key if existing.

... See full list

File

./entity.module, line 720

Code

function entity_key_array_by_property(array $entities, $property) {
  $ret = array();
  foreach ($entities as $entity) {
    $key = isset($entity->{$property}) ? $entity->{$property} : NULL;
    $ret[$key] = $entity;
  }
  return $ret;
}