Last Updated: February 25, 2016
·
379
· horiajurcut

Setting Default Values

Instead of writing:

$params = array(
    'param_one' => null,
    'param_two' => null
);

if (isset($options['param_one'])) {
    $params['param_one'] = $options['param_one'];
}

if (isset($options['param_two'])) {
    $params['param_two'] = $options['param_two'];
}

We can use the + operator for arrays:

$params = $options + array(
    'param_one' => null,
    'param_two' => null
);