Forum Moderators: coopster

Message Too Old, No Replies

PHP Bag of Tricks V

         

jatar_k

5:16 pm on Dec 4, 2008 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



We haven't done one of these in a while and I love starting them off with little tricks with variable variables so

I needed to clean arrays of data and set them as vars in the global scope, pass in an array and use this

$dataarr = array();
$dataarr['myvar1']= 12345;
$dataarr['myvar2']= 23456;
$dataarr['myvar3']= 34567;
$dataarr['myvar4']= 45678;
$dataarr['myvar5']= 56789;
$dataarr['myvar6']= 67890;

foreach ($dataarr as $key => $value) {
global ${$key};
${$key} = mysql_real_escape_string(strip_tags(trim($value)));
}

you could put whatever you want in the loop, anything that needs to happen to every piece

The old threads for your perusal
PHP Bag of Tricks I [webmasterworld.com]
PHP Bag of Tricks II [webmasterworld.com]
PHP Bag of Tricks III [webmasterworld.com]
Good PHP solutions to small problems [webmasterworld.com]

Anyango

3:42 pm on Dec 5, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Variable Functions

I know almost every senior member here knows about them but i also know majority of average programmers don't, anyways i find them cool

<?
$myFunction="date";
echo $myFunction("m-d-Y");
?>