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 07/11/06 10:35

David Haynes wrote:
> Rik wrote:
>> David Haynes wrote:
>>> $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,
> $row['isarchived'] is already a 0/1 value (Tinyint(1)), so really the
> (bool) cast is a no-op. My bad. You could just use $isArchived =
> $row['isarchived']

What do you mean by no-op? I'm no native speaker, please explain. And
already 0/1? 0/1 is an integer, not a boolean.

<?php
$row['test'] = 1; //so, integer 1, can be cast to true
$istrue = (bool)$row['test'];
echo '$row[test] can be cast to ';
echo ($row['test'])?'true':'false';
$string = "\n%s is %sa boolean";
printf($string,'$row[test]',($row['test']===true)? '' :'not ');
printf($string,'$istrue',($istrue===true)? '' :'not ');
?>

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

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