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
Did you know?
PHP applications still send a browser full of JavaScript. Hardening the server does not inventory the payment, analytics, and plugin scripts that run after the HTML is delivered.
Security insights from Cside
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#