Studyon Minte9.com
ZCE 5.3

Study

Data types



        // Numeric: Octal number (0755); Hexadecimal (0xFFF)
	// Strings can be quoted in three ways
	// With double quotes variables are interpreted
	// Php convert between data types transparently
	// It is posible to force the corvension


* Numeric values

Decimal (1, 0, -1, 10, 1452)

<?php echo 10; // Output 10 echo -1; // Output -1 echo 0; // Output 0 echo 1452; // Output 1452
  Octal (0600; 0100) This is Unix style access permision (identified by its leading zero)
<?php echo 0100; // 64 = 1*8^2 + 0*8^1 + 0*8^0
  Hexadecimal (0x123; 0XFF) Base 16 notation (identified by its leadgin 0x case-insensitive)
<?php echo 0x111; // 1*16^2 + 1*16^1 + 1*16^0 = 256 + 16 + 1 = 273 echo 0x112; // 1*16^2 + 1*16^1 + 2*16^0 = 256 + 16 + 2 = 274 echo 0x121; // 1*16^2 + 2*16^1 + 1*16^0 = 256 + 32 + 1 = 289 echo 0xFFF; // 15*16^2 + 15*16^1 + 15*16^0 = 3840 + 240 + 15 = 4095
  Be aware that the float data type is not always capable of representing numbers in the way you expect it to.
<?php echo ((0.1 + 0.7) * 10); // output 8 echo (int) ((0.1 + 0.7) * 10); // output 7 // This happens because the result of this simple arithmetic expression is stored internally as 7.999999 // instead of 8; when the value is converted to int, PHP simply truncates away the fractional part.
  * Strings Single quotes (variables and escape sequences will not be interpreted and replaced)
<?php $a = 'a'; echo $b = '$an'; // output $an
  Double quotes (variables and escape sequences will be interpreted and replaced)
<?php $a = 'a'; echo $b = "$an"; // output a
  Herodoc (for multiple lines). Allow for the use of quotes without escaping.
<?php $who = "John"; $output = <<<TEST She said "This is $who's test" on multiple rows TEST; echo nl2br($output); /* output She said "This is John's test" on multiple rows */
  * Boolean A number converted into boolean became false if the original value is zero, and true otherwise.
<?php echo ((boolean) 0) !== TRUE; // output 1 echo ((boolean) 99) === TRUE; // output 1
  A string is converted to false only if its empty or '0'. If it contains any other data (even multiple zeros) it is converted to true.
<?php echo ((boolean) '0') === FALSE; // output 1 echo ((boolean) '00') === FALSE; // output nothing
  * Array - Are containers of data elements * Object - Are containers of both data and code * NULL A variable is considered to be NULL if it has been assigned the special value NULL, or if it has not yet been assigned a value at all. * Converting Between Data Types PHP takes care of converting between data types transparently. However, it is still possible to force the conversion of a value to a specific type
<?php $x = 10.88; echo (int) $x; // output 10
 


http://www.blueshoes.org/en/developer/syntax_exam/