luya\helpers\ArrayHelper::arrayUnshiftAssoc PHP Méthode

arrayUnshiftAssoc() public static méthode

Prepend an assoc array item as first entry for a given array.
public static arrayUnshiftAssoc ( array &$arr, string $key, mixed $val ) : array
$arr array The array where the value should be prepend
$key string The new array key
$val mixed The value for the new key
Résultat array
    public static function arrayUnshiftAssoc(&$arr, $key, $val)
    {
        $arr = array_reverse($arr, true);
        $arr[$key] = $val;
        return array_reverse($arr, true);
    }

Usage Example

Exemple #1
0
 public function addField($pointer, $field, array $options = [])
 {
     if ($this->hasField($pointer, $field)) {
         return false;
     }
     $options = ArrayHelper::merge(['name' => null, 'i18n' => false, 'alias' => null, 'plugins' => [], 'i18n' => false, 'extraField' => false], $options);
     // can not unshift non array value, create array for this pointer.
     if (empty($this->_config[$pointer])) {
         $this->_config[$pointer] = [];
     }
     $this->_config[$pointer] = ArrayHelper::arrayUnshiftAssoc($this->_config[$pointer], $field, $options);
     return true;
 }
All Usage Examples Of luya\helpers\ArrayHelper::arrayUnshiftAssoc