Tips-A2Z home page


Sub-categories

(None)

Category  |   Discussion (0)PHP

Main > Technology > Computers > Programming > PHP
Variable functions: In some cases you might want a user to choose which function to apply on some values. You can use a variable to call the function. e.g.,

<?php 

function sum($v1, $v2) { return ($v1 + $v2); }

function minus($v1, $v2) { return ($v1 - $v2); }



$function = "sum";

print $function(10,5).'<br>';

$function = "minus";

print $function(10,5).'<br>';

?>

It's essential that you use the same number of parameters.   Kevin Solway (173)

– –– ——— –– –

Main > Technology > Computers > Programming > PHP
Slashes and quotes: Make sure you thoroughly test your PHP code when it displays text that may contain quotes and slashes (such as "John's/Jonathan's"). This should be tested both with "magic_quotes" turned on, and also with it turned off. Very few sites get this right, and you will often see displayed text, such as product names, which contain any number of slashes that shouldn't be there.   Kevin Solway (173)

– –– ——— –– –


 


 

To post a new tip, sign up for a free account.
(Unfortunately this is a necessary spam prevention measure)

Who is online
In total there are 47 users online :: 0 registered and 47 guests (based on users active over the past 5 minutes)