a::get($array, $key, $default = null)

Gets an element of an array by key

  • $array (array)
    The source array
  • $key (mixed)
    The key to look for
  • $default (mixed)
    Optional default value, which should be returned if no element has been found
  • return (mixed)

Example

<?php
$array = array(
  'cat'  => 'miao',
  'dog'  => 'wuff',
  'bird' => 'tweet'
);

echo a::get($array, 'cat');
// output: 'miao'

echo a::get($array, 'elephant', 'shut up');
// output: 'shut up'

$catAndDog = a::get(array('cat', 'dog'));
// result: array(
//   'cat' => 'miao',
//   'dog' => 'wuff'
// );

Is something missing or incorrect? Edit this page on Github…