Do you have a question? Post it now! No Registration Necessary. Now with pictures!
- Posted on
July 4, 2008, 5:00 pm
rate this thread
if ($b[$a]) $a=$b[$a]
(The IF is actually usually an isset() or != '' ... bu you get the
I do it a lot, and it's really... awkward, both in terms of code and
the logical flops involved. I'm clearing info being passed to DB
queries, so a typical example might be:
$a = 'first'; //A value passed through a query string;
$b = array( 'first' => 'first_name',
'last' => 'last_name' ); //A conversion array. Some of
these are extremely complicated and swap out dependent on
circumstances, so I'm pretty happy with this as a way of double-
checking my queris befroe the hit the $sql;
if ( $b[$a] != '' ) $a = $b[$a]; //Get 'first_name';
Lookid how logn that was! And I had to repeat the array nest twice!
It's not that big a deal- except the ACTUAl queries I'm working on are
a bit more like...
if ( isset($this->sort_order[$extra['sort_order']]) )
$extra['sort_order'] = $this->sort_order[$extra['sort_order']];
...yeah. Is there a simple way to perform this operation WITHOUT
writing a custom function that I'm missing?
July 4, 2008, 5:37 pm
- The Natural Philosopher
July 4, 2008, 6:52 pm