Elgg\Database\MetadataTable::createFromArray PHP Method

createFromArray() public method

To achieve an array for a single key, pass in the same key multiple times with allow_multiple set to true. This creates an indexed array. It does not support associative arrays and there is no guarantee on the ordering in the array.
public createFromArray ( integer $entity_guid, array $name_and_values, string $value_type, integer $owner_guid, integer $access_id = ACCESS_PRIVATE, boolean $allow_multiple = false ) : boolean
$entity_guid integer The entity to attach the metadata to
$name_and_values array Associative array - a value can be a string, number, bool
$value_type string 'text', 'integer', or '' for automatic detection
$owner_guid integer GUID of entity that owns the metadata
$access_id integer Default is ACCESS_PRIVATE
$allow_multiple boolean Allow multiple values for one key. Default is false
return boolean
    function createFromArray($entity_guid, array $name_and_values, $value_type, $owner_guid, $access_id = ACCESS_PRIVATE, $allow_multiple = false)
    {
        foreach ($name_and_values as $k => $v) {
            $result = $this->create($entity_guid, $k, $v, $value_type, $owner_guid, $access_id, $allow_multiple);
            if (!$result) {
                return false;
            }
        }
        return true;
    }