Re: conditional statement problems

From: Date: Tue, 01 Oct 2002 08:05:38 +0000
Subject: Re: conditional statement problems
References: 1 2  Groups: php.general 
Request: Send a blank email to php-general+get-118328@lists.php.net to get a copy of this message
René Moonen wrote:
Pablo Oliva wrote:
$title_err = ($adTitle == "") ? 1 : strlen($adTitle) > 50 ? 2 : 0; Can anyone tell me why this is not evaluating correctly (returning a value of 1) when $adTitle is an empty string?
I have no idea... but if you change your code to this, it works: $title_err = ($adTitle == "") ? 1 : (strlen($adTitle) > 50 ? 2 : 0); Does anyone know why ? René Yes... that's it. Your statement is probably evaluated like this:
$title_err = ( ($adTitle == "") ? 1 : strlen($adTitle) > 50 ) ? 2 : 0; The first ?: returns 1 so the second ?: will return 2 Regards René

« previous php.general (#118328) next »