Re: $POST and $_SESSION

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 3/15/2012 9:04 AM, Tedd Sperling wrote:
What's a better/shorter way to write this?

$first_name = $_SESSION['first_name'] ? $_SESSION['first_name'] : null;
$first_name = isset($_POST['first_name']) ? $_POST['first_name'] : $first_name;
$_SESSION['first_name'] = $first_name;

Better:
$first_name = null;
if (isset($_POST['first_name'])) {
	$first_name = $_POST['first_name'];
	$_SESSION['first_name'] = $first_name;
} elseif (isset($_SESSION['first_name'])) {
	$first_name = $_SESSION['first_name']
}

Shorter:
$first_name = @$_POST['first_name'] ?: (@$_SESSION['first_name'] ?: null);
$_SESSION['first_name'] = $first_name;


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux