View Single Post
Old 07-10-2008, 09:31 AM   #4 (permalink)
sketchMedia
The Prestige
Advanced Programmer Top Contributor Good Samaritan 
 
sketchMedia's Avatar
 
Join Date: Oct 2007
Location: Manchester, UK
Posts: 836
Thanks: 31
sketchMedia is on a distinguished road
Default

post or pre incrementing/decrementing depends on what you need the script to do, both can produce very different results, consider this:
PHP Code:
<?php

$a 
$b 1;

$c = ++$a;
$d $b++;

printf('$a: %d <br /> $b: %d <br /> $c: %d <br /> $d: %d',$a$b$c$d);
This script may not produce the results expected. In this script we set up our base vars ($a, $b) next we create $c and assign it the the value of ++$a, in other words 'Increment $a then put then assign $c the value'. Next we create $d and assign it the the value of $b++, in other words 'Assign $d the value of $b, then increment $b'. If we were to print this it would produce:
Code:
2
2
2
1
The speed difference comes because when you use post increment or decrement ($i++) PHP copies the value to a tmp variable, then it increments the value and returns the value which was stored before the incrementation, pre increment/decrement however does not, it just returns the value of the variable +/- 1

Anyway back to the topic, yes you are right C has no native boolean type (to my knowledge, prior to C99)
, instead you use 0 or 1 to flag true or false or you can use #define's or enum's:
Code:
#define TRUE  1
#define FALSE 0    
//or
typedef enum { FALSE, TRUE } boolean;
or user C99's stdbool:
c Code:
#include<stdbool>
bool boolean = true;
//etc
 
However php considers all these values as (Boolean)FALSE:
  • the boolean FALSE itself
  • the integer 0 (zero)
  • the float 0.0 (zero)
  • the empty string, and the string "0"
  • an array with zero elements
  • an object with zero member variables (PHP 4 only)
  • the special type NULL (including unset variables)
  • SimpleXML objects created from empty tags
taken from: PHP: Booleans - Manual
__________________
mysql> SELECT * FROM `users` WHERE `users`.`clue` > 0;
Empty set (0.00 sec)

Last edited by sketchMedia : 07-10-2008 at 03:15 PM. Reason: error in explaination
sketchMedia is offline  
Reply With Quote