<?php
// question
/***
what the heck does (int) do??
never seen (x) before
***/
// answer, long version
/*****
An 'id' is usually a whole number
if we have 99 users, they have id number 1-99
if we refer to user 22 as '22.00003' there can become an error
Now some operations in php can change integer (int) into float, even if not should be
Can become a (float) be accident. (float) are 3.7 and 0.005 and 22.0 and 22.00003
After such an operation, we can use (int) to secure it is 22 and not 22.00
*****/
///////////////////////////////////////////////////
// here we set $thispage_id to 22.01
$thispage_id = 22.01;
echo "this page number is: $thispage_id <br>";
// make sure this_page_id is an integer (int)
$thispage_id = (int)$thispage_id;
echo "this page number is now: $thispage_id <br><br>";
// (int) has some sisters: (float) (string) (boolean)
// we can make a string out of a number. String is characters in a text.
$thispage_id = (int)22;
// here is it is an integer NUMBER
// make another variable, a string version of $thispage_id
$string_of_id = (string)$thispage_id;
// $string_of_id is a string: "22"
///////////////////////////////////////////////////
// let us set two variables, one integer and one string, both with value 22
$var1 = 22;
$var2 = "22";
// now test if VALUE is identical, regardless of type (int, string)
if ( $var1 == $var2 )
echo "first test say $var1 is == $var2 <br>";
else
echo "first test say $var1 is NOT == $var2 <br>";
// now test if VALUE AND TYPE of variable (int, string) is identical
if ( $var1 === $var2 )
echo "second test say $var1 is === $var2 <br>";
else
echo "second test say $var1 is NOT === $var2 <br>";
// difference in our tests is == or ===
// === requires, BOTH value AND type be identical
// then if( something1 === something2 ) is regarded to be TRUE
?>
If you run halojoy script code above, output will be:
this page number is: 22.01
this page number is now: 22
first test say 22 is == 22
second test say 22 is NOT === 22
halojoy is NOT same as "halojoy"
he is different
😉
.