What is the difference between == and === in PHP?

It basically works on the variable types (int, string etc..) So when using === it basically checks to see if the types are the same.. Let me show you with an example:

<?php
	
	$number = (int) 1;
	$number2 = (string) "1";
	
	if($number == $number2)
	{
		echo '== Match';
	}else{
		echo '== Doesnt match';
	}
?>

This would return true, because the values are the same and we're only comparing the values.

<?php
	
	$number = (int) 1;
	$number2 = (string) "1";
	
	if($number === $number2)
	{
		echo 'They match';
	}else{
			echo '=== Doesnt match';
	}	
?>

This wouldn't match because number 1 is an int, and number 2 is a string.

Let me know if this helps you =)

commented: Useful post +6
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.