Joined February 2014
·
Posted to
default value for a variable
over 1 year
ago
@blainesch put a simple method using ternary operator:
https://coderwall.com/p/h5t7rq
$foo = $bar ?: $baz ?: $quz;
Posted to
Tips for cron file (PHP)
over 1 year
ago
- I really doub it, this is a micro optimization.
- It depends on the contents of $array[$i]['key'] if is a scalar value then $var is a copy, if is an object is a reference to the same object...
Do you have any documentation or test about it ?
Posted to
Simple Template Renderer in php
over 1 year
ago
strtr is a good choice but remember to put a prefix and postfix:
foreach($a as $key=>$value) { $b['{$' . $key . '}'] = $value }
return strtr($subject, $b) ;
If you think is better to use regexp then I recommend you to use pregmatchall and preg_split. In that way the source of keys won't be your array, the list of required keys are based on the template. Avoiding the problem of a tiny template with a fat array of options making unnecesary comparisons
Achievements
30 Karma
964 Total ProTip Views
Charity
Fork and commit to someone's open source project in need
Lab
Have at least one original repo where C# is the dominant language
nope. 5.4 is the rigth version http://php.net/manual/en/migration54.new-features.php