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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.