You are here: Re: Passing Boolean to a Function « PHP Programming Language « IT news, forums, messages
Re: Passing Boolean to a Function

Posted by Rik on 12/17/92 11:52

David Haynes wrote:
> Greg Scharlemann wrote:
>> David Haynes wrote:
>>> Also, var is deprecated in PHP5.
>> Thanks!
>> Your test case also worked... but I'm going to make my question a
>> little more complicated...
>>
>> That boolean value is going to be written to a MySQL database. I've
>> set the column to be of type Bool (which appears to turn into a
>> Tinyint(1)), is that the best approach? Should I use enum('true',
>> 'false') or some other approach?
>
> I would translate the 0/1 from MySQL into true/false at the lowest
> level I could. It's not all that hard to unroll it as follows:
>
> $result = mysqli_query($sql);
> while( $row = mysql_fetch_assoc($result) ) {
> $isArchived = $row['is_archived'] ? true : false;
> ...
> }


$isArchived = (bool)$row['isarchived'];
it's shorter, and by using $row['is_archived'] ? you're already evaluating
the boolean value.


http://www.php.net/manual/en/language.types.boolean.php#language.types.boolean.casting

Grtz,
--
Rik Wasmus

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация