PDA

View Full Version : [PHP] "!"'s



wsg14
16-11-2008, 10:18 PM
if($data['username'] == $username){

}

How would I make that code do tho following: if $data['username'] (doesn't equal) $username{ }.

I know you have to use an exclamation mark somewhere (!) but I don't know where. +rep

Agnostic Bear
16-11-2008, 10:20 PM
if($data['username'] == $username){

}How would I make that code do tho following: if $data['username'] (doesn't equal) $username{ }.

I know you have to use an exclamation mark somewhere (!) but I don't know where. +rep

!= $username

wsg14
16-11-2008, 10:20 PM
thanks.

Iszak
17-11-2008, 12:44 PM
Just something you might want to take note on, when checking if something is true or false it is in fact quicker to use === compared to == and same applies with !== and !=, and I believe it would be a good practice to do so to micro-optimize in advance. Also some benchmarking I did also found that comparing a variable to a string with ===, compared to == is also faster but in the end it's up to you and the conditions you are faced with.

Agnostic Bear
17-11-2008, 05:44 PM
Just something you might want to take note on, when checking if something is true or false it is in fact quicker to use === compared to == and same applies with !== and !=, and I believe it would be a good practice to do so to micro-optimize in advance. Also some benchmarking I did also found that comparing a variable to a string with ===, compared to == is also faster but in the end it's up to you and the conditions you are faced with.

It's also not the same thing at all, === is a strict match where == is a regular match.

$hello = 0;
$hallo = '0';



if( $hallo == $hello )
{
echo 'hello<br />';
}
if( $hallo === $hello )
{
echo 'hallo<br />';
}


You should be able to figure it out from that.

Iszak
17-11-2008, 06:06 PM
I'm aware of this Jewish Bear. I do know what I'm talking about, the === operator matches the type too be it string, int, float, double, etc. Amazing that someone actually know's what they're talking abut before posting aye? In his case if he used === it would be plausible because they'll both be strings if I'm not mistaken.

Example, just because I can. (Not Relevant)


<?php

$int = 10;
$float = 10.0;

if ($int === $float)
{
echo "They're the same!";
}

?>
Edit: Just re-read my post (the prior one) no where did I say that they're the same thing. I was saying it was quicker to use the === operator when comparing true or false implying that true and false were not strings and they're both in the same form of true/false e.g. 1 and 0 or true and false. But no where did I say === and == are the same, so I don't know where you got this idea from.

Calon
17-11-2008, 11:42 PM
How many threads have you actually created?

You should just read a few tutorials.

Want to hide these adverts? Register an account for free!