a::update($array, $update)

Updates an array with a second array

  • since: Kirby 2.3.0
  • $array (array)
  • $update (array)
  • return (array)

Example

// original array
$source = [
  'a' => 'value a',
  'b' => 'value b'
];

// array with updated values
$result = a::update($source, [
  'a' => 'updated value a',
  'c' => 'new value c'
]);

/**
 * array(
 *   'a' => 'updated value a',
 *   'b' => 'value b',
 *   'c' => 'new value c'
 * )
 */

Callbacks

The second parameter $update can be an array containing callbacks as values, which will get the original values as argument.

$source = [
  'a' => 'value a',
  'b' => 'value b'
];

$result = a::update($source, [
  'a' => function($value) {
    return 'updated ' . $value;
  }
]);