Posted by Rik on 05/30/06 17:50
Ian Davies wrote:
>> $_SESSION[key] = (isset($_POST[key])) ? trim($_POST[key]) :
>> $_SESSION[key];
> Your a saviour Rik cheers
> Works a treat.
> out of interest what is the script doing? I cant work it out
Search www.php.net for ternary operator:
http://nl2.php.net/manual/en/language.operators.comparison.php
Actually, it does the following:
if(isset($_POST[key]){ //checks wether a new $_POST value with the specific
key exists
$_SESSION[key] = trim($_POST[key]); //sets the session value to the
posted value
} else {
$_SESSION[key] = $_SESSION[key]; //keep the session variable the same as
it was
}
The ternary operator just saves a lot of lines in the code while doing
simple checks.
Grtz,
--
Rik Wasmus
[Back to original message]
|