Data Types
/* Integers and floats
Integers hold whole numbers, while floats hold fractions */
//no doble quotes
<?php
$one = 1;
$two = 2;
$three = 3;
$string_one = "1";
?>
<ul>
<li><?php echo $one ?></li>
<li><?php echo gettype($one) ?></li> //get type integer
<li><?php echo $string_one ?></li>
<li><?php echo gettype($string_one) ?></li>// get type string
</ul>
//add two integers and substract
<?php
echo $one + $two - $three;
?>
//floats
<?php
$distance_to_home = 1.2;
$distance_to_work = 2.5;
?>
<?php
echo $distance_to_home + $distance_to_work + $three;
?>
/* Booleans
true or false - to define a boolean use the keyword true or false
true = anything that is non 0 value is considered true
false = 0 value and empty string */
<?php
$bool = TRUE;
var_dumo($bool); //dumb print bool(true)
$bool = FALSE;
var_dumo($bool); //dumb print bool(false)
?>
//typecast to see if is true or false
<?php
var_dumo((bool)""); // empty string - all false
var_dumo((bool) 0); //
var_dumo((bool) 0.0);//
var_dumo((bool) array()); // empty array
?>
// all report back as bool(false)
<?php
var_dumo((bool)"abc"); // string - all true
var_dumo((bool) 1); //
var_dumo((bool) 1.0);//
var_dumo((bool) -1); //
?>
// all report back as bool(true)
/* Strings
display text \n is a brake <br> */
<?php
$greeting = "Hello, friends: \n";
$greeting(0) = "j";
$secondary_greeting = "How are you";
?>
<?php
echo $greeting; // with j = Jello, friends
echo $greeting(0); // first character of Hello - H
echo $greeting(1); // second character of Hello - e
echo $secondary_greeting; // eco secondary greeting
?>
/* 7 Data Types on php - ways to hold data
Integers = hold whole numbers
floats = fractional numbers 0.2
string = letters and sentences
arrays = store multiple data types in an organize way
booleans = to define objects true or false
objects = complex variables (they are the base of object oriented php)
resources = anything that is not php data - files response for database queries
*/