assigning either/or values

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
mad_phpq
Forum Commoner
Posts: 85
Joined: Fri Apr 27, 2007 5:53 am

assigning either/or values

Post by mad_phpq »

hi, i've seen this somewhere before, but how can i put this onto one line?

Code: Select all

$value = $_POST['value'];
if ( $value = '' )
	$value = $_GET['value'];

User avatar
maliskoleather
Forum Contributor
Posts: 155
Joined: Tue May 15, 2007 2:19 am
Contact:

Post by maliskoleather »

Code: Select all

$value = empty($_POST['value'])?NULL:$_POST['value'];
mad_phpq
Forum Commoner
Posts: 85
Joined: Fri Apr 27, 2007 5:53 am

Post by mad_phpq »

great! thanks. I take it is has to be

Code: Select all

$value = empty($_POST['value'])?NULL:$_GET['value'];
User avatar
maliskoleather
Forum Contributor
Posts: 155
Joined: Tue May 15, 2007 2:19 am
Contact:

Post by maliskoleather »

its just easier to me that way..

it just needs to be

var = (logic or function)? true value : false value;

ofcourse, thats assuming your function in the logic area returns a boolean :wink:
Post Reply