Jump to content

really really basic question


robert_gsfame

Recommended Posts

what do u mean identical and equal, i really confused

this is not about mysql but javascript function and php

 

could u please explain a bit.....equal means everything that cope with number and identical for character??

Yes. What I mentioned works in PHP and most probably Javascript.

 

= - Assignment

== - Value equality

!= - Value inequality

=== - Type and value equality

!== - Type and value inequality

 

$date = '1';
//$date now contains the value of 1.
if($date == '1') {
//Checks if $date has the value of 1, and returns true.
if($date != '2') {
//Checks if $date does not have the value of two, and returns true.

Can't think of examples with === and !==

Though, what is explained above is all true. :) You'll probs be needing != in your statement

okay so anything that deals with string, !== must be used instead of != which should be used for numeric (integer)

Nope, not necessarily. I'll use a real-life example with the function strpos.

 

strpos is a function that searches whether a substring of a string exists. If so, it returns the index at where the substring starts at. One possible return value is 0 (which means at the beginning of the string).

 

strpos("phpfreaks", "php");

The string php is at the start of phpfreaks so strpos returns the number 0.

 

However, if the substring is not found, strpos returns the boolean value false.

 

strpos("phpfreaks", "o");

o is not in phpfreaks, so it returns false.

 

Now, say you want to check if a substring is in a string. If you used == it won't work because 0 == false; however 0 !== false.

 

if (strpos("phpfreaks", "o") === false) // o is not in phpfreaks

 

Hope this helps.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.