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
);
Written by Horia Jurcut
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Php
Authors
Related Tags
#php
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#