|
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]
|