When code is always written the way that it's written, it sometimes takes an outsider voice to question the rote.
Today I present to you a PHP puzzler that in fact had me stumped for a day or two. I do enjoy when a language throws a curve ball; it presents an opportunity to gain insight on the mechanics and become acquainted with the nuances of the language in question.… Read the rest
Inspired by a thread on Facebook to which I contributed, a few words concerning readable code vs compact code.
When writing applications, a common scenario involves setting a variable from some external source. What immediately ensues is a check to ensure that our variable has some meaningful value.… Read the rest
One of PHP’s less known language constructs is list(), very useful for unpacking indexed arrays. Consider the following simple example denoting its usage:
//populate an array with values
$record= array('me', '1.800.123.4567', 'firstname.lastname@example.org');
//unpack the array into variables, skipping the phone number
list($name, , $email) = $record;
//print the output
echo("name: $name; email: $email");
This clean, readable, scalable approach is great for processing data records, unpacking an SQL result row, etc.… Read the rest