Joined February 2014
·

Carlos C Soto

Mexico
·
·
·

Posted to Arrays in PHP 5.5 over 1 year ago
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
  1. I really doub it, this is a micro optimization.
  2. 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
970 Total ProTip Views
Interests & Skills