Hey Guys,welcome back to my channel Ndev tuts. In this tutorial,we will learn about scalar datatypes and types of scalar datatypes each in details and also i will show you how to use them effectively in the program. Let’s talk about scalar datatypes in php. A variable is a scalar when it holds a single value. php has four scalar datatypes including integer,float,string and Boolean. Let’s talk about integer datatype. an integer datatype is a non decimal number it can hold only whole numbers including positive number like 1,5 etc and also included negative number like -3,-4 etc. it can hold number without fractional part or decimal point. The range of integers must lie between this. Let’s see the example of integer datatype. Create a new php file integer.php Let’s start writing a code. here to write your code create one variable $x it hold integer value the default base is decimal base 10. var_dump()function return datatype and value save the code Let’s run the program. this the output screen. integer can be octal integer base 8 or hexadecimal base 16. The octal integers can be declared with leading 0. here to create on octal integer number. save the code Let’s run the program refresh the output screen this is the octal integer number. the hexadecimal integer can be declared with leading 0x. here to create one hexadecimal number save this code Let’s run the program refresh the output screen this is the hexadecimal number this all are integer variables. Let’s talk about float datatype A floating point number is a number with a decimal point or a number in exponential form. Let’s see the example of float datatype 1st of to create one a php file float.php Let’s start writing a code here to create one variable $x its hold floating point number save the code Let’s run the program This is the floating point number Let’s talk about string datatype: A string is a sequence of characters where every character is the same as a byte like “Hello World”. A string can be any text inside quotes.you can use single or double quotes.it can hold letters,alphabets,numbers and special characters and it can be as large as up to 2 gb. Let’s see the example of string datatype. here to create a php file. string.php Let’s start writing a code here to create one string variable string are written within double quotes during declaration. The string can also be written within single quotes but it will be treated differently while printing variables. to clarify this look at in this example. save the code Let’s run the program This is the output screen.here to see two output. 1st output is to declared string within double quotes at that time it will be print text and fetch the value of variable. and in 2nd output to declared string within single quotes at that time it will be print only text and not fetch the value of variable. Let’s talk about Boolean datatype Boolean datatype hold only two values, either true or false when successful events will return true and unsuccessful events return false. Boolean are often used in conditional testing. you will learn more about conditional testing in my upcoming tutorials. Null type values are also treated as false in Boolean. part from null,0 is also consider as false in Boolean. if a string is empty than it is also considered as false in Boolean datatype. Let’s see the example of Boolean datatype 1st of all to create one php file boolean.php Let’s start writing a code here to create a one boolean variable here to set the value of variable by default save the code let’s run the program this is the output screen and here to see Boolean variable

Scalar Datatypes in PHP

Leave a Reply

Your email address will not be published. Required fields are marked *