[PHP] Re: ternary operator sintax help
?= (isset($erros['anexo']) ? 'div class=mensagemErro'.$erros['anexo'].'/div' :''); ? MEM tal...@gmail.com escreveu na mensagem news:002401ca46b4$ed6ad6a0$c84083...@com... Hello all, I'm trying to display a div, only when some php value is set. Since this will be near html, I'd like to keep it on one line. So, I'd love to use shortcuts and a ternary operator for the effect. I'm having something like this right now, but the div still appears even if the error is NOT set. ?= (isset($erros['anexo'])) ? 'div class=mensagemErro' .$erros['anexo'].'/div' :''; ? :( Can I have your help with the right syntax ? Regards, The newbie on a Humpty Dumpty wall, Márcio -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Re: ternary operator sintax help
Sorry all, It's ok. The sintax: ?php echo (isset($erros['anexo']) ? 'div class=mensagemErro'.$erros['anexo'].'/div' :''); ? Was right all the time. Anyway, I've learn something new: having a var with '' is not the same thing as not been unset. So we must pay attention on what cases we use isset, or !empty. Thanks a lot, Márcio -Original Message- From: João Cândido de Souza Neto [mailto:j...@consultorweb.cnt.br] Sent: terça-feira, 6 de Outubro de 2009 19:53 To: php-general@lists.php.net Subject: [PHP] Re: ternary operator sintax help ?= (isset($erros['anexo']) ? 'div class=mensagemErro'.$erros['anexo'].'/div' :''); ? MEM tal...@gmail.com escreveu na mensagem news:002401ca46b4$ed6ad6a0$c84083...@com... Hello all, I'm trying to display a div, only when some php value is set. Since this will be near html, I'd like to keep it on one line. So, I'd love to use shortcuts and a ternary operator for the effect. I'm having something like this right now, but the div still appears even if the error is NOT set. ?= (isset($erros['anexo'])) ? 'div class=mensagemErro' .$erros['anexo'].'/div' :''; ? :( Can I have your help with the right syntax ? Regards, The newbie on a Humpty Dumpty wall, Márcio -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: ternary operator sintax help
On Oct 6, 2009, at 2:26 PM, MEM wrote: Sorry all, It's ok. The sintax: ?php echo (isset($erros['anexo']) ? 'div class=mensagemErro'.$erros['anexo'].'/div' :''); ? Was right all the time. Anyway, I've learn something new: having a var with '' is not the same thing as not been unset. So we must pay attention on what cases we use isset, or !empty. Thanks a lot, Márcio -Original Message- From: João Cândido de Souza Neto [mailto:j...@consultorweb.cnt.br] Sent: terça-feira, 6 de Outubro de 2009 19:53 To: php-general@lists.php.net Subject: [PHP] Re: ternary operator sintax help ?= (isset($erros['anexo']) ? 'div class=mensagemErro'.$erros['anexo'].'/div' :''); ? MEM tal...@gmail.com escreveu na mensagem news:002401ca46b4$ed6ad6a0$c84083...@com... Hello all, I'm trying to display a div, only when some php value is set. Since this will be near html, I'd like to keep it on one line. So, I'd love to use shortcuts and a ternary operator for the effect. I'm having something like this right now, but the div still appears even if the error is NOT set. ?= (isset($erros['anexo'])) ? 'div class=mensagemErro' .$erros['anexo'].'/div' :''; ? :( Can I have your help with the right syntax ? Another one to consider... strlen ($item) 0 ? 'not empty' : 'empty'; Because empty() will return true if 0 is the value, sometimes you have to check for the length of the item. ~Philip -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: ternary operator sintax help
just as ashley said it. On 10/6/09 3:26 PM, MEM tal...@gmail.com wrote: Sorry all, It's ok. The sintax: ?php echo (isset($erros['anexo']) ? 'div class=mensagemErro'.$erros['anexo'].'/div' :''); ? Was right all the time. Anyway, I've learn something new: having a var with '' is not the same thing as not been unset. So we must pay attention on what cases we use isset, or !empty. Thanks a lot, Márcio -Original Message- From: João Cândido de Souza Neto [mailto:j...@consultorweb.cnt.br] Sent: terça-feira, 6 de Outubro de 2009 19:53 To: php-general@lists.php.net Subject: [PHP] Re: ternary operator sintax help ?= (isset($erros['anexo']) ? 'div class=mensagemErro'.$erros['anexo'].'/div' :''); ? MEM tal...@gmail.com escreveu na mensagem news:002401ca46b4$ed6ad6a0$c84083...@com... Hello all, I'm trying to display a div, only when some php value is set. Since this will be near html, I'd like to keep it on one line. So, I'd love to use shortcuts and a ternary operator for the effect. I'm having something like this right now, but the div still appears even if the error is NOT set. ?= (isset($erros['anexo'])) ? 'div class=mensagemErro' .$erros['anexo'].'/div' :''; ? :( Can I have your help with the right syntax ? Regards, The newbie on a Humpty Dumpty wall, Márcio -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Re: ternary operator sintax help
Absolutely. ;) I was reporting to ashley teachings. :-) Philip, thanks for the tip. :-) Thank you all, Márcio -Original Message- From: Tom Worster [mailto:f...@thefsb.org] Sent: terça-feira, 6 de Outubro de 2009 21:10 To: MEM; php-general@lists.php.net Subject: Re: [PHP] Re: ternary operator sintax help just as ashley said it. On 10/6/09 3:26 PM, MEM tal...@gmail.com wrote: Sorry all, It's ok. The sintax: ?php echo (isset($erros['anexo']) ? 'div class=mensagemErro'.$erros['anexo'].'/div' :''); ? Was right all the time. Anyway, I've learn something new: having a var with '' is not the same thing as not been unset. So we must pay attention on what cases we use isset, or !empty. Thanks a lot, Márcio -Original Message- From: João Cândido de Souza Neto [mailto:j...@consultorweb.cnt.br] Sent: terça-feira, 6 de Outubro de 2009 19:53 To: php-general@lists.php.net Subject: [PHP] Re: ternary operator sintax help ?= (isset($erros['anexo']) ? 'div class=mensagemErro'.$erros['anexo'].'/div' :''); ? MEM tal...@gmail.com escreveu na mensagem news:002401ca46b4$ed6ad6a0$c84083...@com... Hello all, I'm trying to display a div, only when some php value is set. Since this will be near html, I'd like to keep it on one line. So, I'd love to use shortcuts and a ternary operator for the effect. I'm having something like this right now, but the div still appears even if the error is NOT set. ?= (isset($erros['anexo'])) ? 'div class=mensagemErro' .$erros['anexo'].'/div' :''; ? :( Can I have your help with the right syntax ? Regards, The newbie on a Humpty Dumpty wall, Márcio -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php