So we are going to learn of what kind of data types in PHP.
Let's get started with variables, start with $, followed by letter or underscore, with no spaces.
Variables determine a vary, we use echo to see our variables value. Variables can be a number or words, if you're using words, put " and " then strings.Code:<html> <head> <title>variables</title> </head> <body> <?php $var1 = 10; echo $var1; echo </ br> $var2 = "hello world"; echo $var2; ?> </body> </html>
fyi, hello world is a stringCode:<html> <head> <title>strings</title> </head> <body> <?php echo "hello world"; ?> </body> </html>
now for numbers we can do simple math
if we use a variable set to 10+!, in our browser we get 11Code:<html> <head> <title>numbers</title> </head> <body> <?php $var1 = 10; echo ($var1 + 1); ?> </body> </html>
arrays
arrays are basicly more than one variable in the same arrayCode:<html> <head> <title>arrays</title> </head> <?php $array1 = array (3,8,15,16,23,42); echo $array[1]; ?>
and as you can see i echoed array 1, wich will give us number 8, because arrays start from 0
booleans and NULL ( true or false )
If I writen 2 variables and asked if var1, var2, and var3 are true or falseCode:<html> <head> <title>booleans and NULL</title> </head> <body> <?php $bool1 = true; $bool2 = false; $var1 = 3; $var2 = "cat"; echo isset($var1); echo isset($var2); echo isset($var3); ?> </body> </html>
in our browser you can see that you will get number 1 ( true ) for var1 and var2, but nothing for var3 because it is false
constants
they are very similar to variables except they dont vary and it doesn't have $ before, because its a constantCode:<html> <head> <title>constants</title> </head> <body> <?php $max_width = 980; define("MAX_WIDTH", 980); echo MAX_WIDTH; >? </body> </html>


LinkBack URL
About LinkBacks




Reply With Quote
Bookmarks