1 / 13

PHP – Data Types

PHP – Data Types. PHP supports 8 data types: boolean, integer, float, string (scalar types) array, object (compound types) resource, NULL (special types). PHP – booleans. Use keywords true or false Both are case insensitive Can typecast a value to boolean, using (bool) or (boolean)

Download Presentation

PHP – Data Types

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. PHP – Data Types • PHP supports 8 data types: • boolean, integer, float, string (scalar types) • array, object (compound types) • resource, NULL (special types)

  2. PHP – booleans • Use keywords true or false • Both are case insensitive • Can typecast a value to boolean, using (bool) or (boolean) • Usually not necessary: automatic conversion to boolean if boolean value is needed

  3. PHP – booleans • When converted to boolean, the following values are considered false: • boolean false, integer 0, float 0.0, empty string, string “0”, an array with 0 elements, an empty object, the special type NULL • everything else is true

  4. PHP – integers • Positive or negative • Decimal, hex, or octal notation • $num1 = 879; // decimal notation • $num2 = 0xAB45; // hex notation • $num3 = 047; // octal notation

  5. PHP – floating point numbers • Positive or negative • $a = 1.234; • $b = 1.2e3; • $c = 7E-10; • /* If an integer value overflows, it is automatically converted to a float */

  6. PHP – strings • A string is a series of characters (there is no size limitation) • Single quotes • Double quotes • heredoc syntax

  7. PHP – strings: single quotes • No expansion of variables and escape sequences, except ‘ and \: • // Outputs: Arnold said: "I'll be back"echo 'Arnold said: "I\'ll be back"'; • // Outputs: You deleted C:\*.*?echo 'You deleted C:\\*.*?'; • // Outputs: You deleted C:\*.*?echo 'You deleted C:\*.*?';

  8. PHP – strings: double quotes • Expansion of variables and escape sequences • \$  $ • \\  \ • \”  “ • \t, \n, …  tab, new line, .. • $num  value of $num

  9. PHP – strings: Heredoc syntax • <<< followed by an identifier • Same identifier to close the quotation, followed by a semicolon ( ; ) • Closing identifier must begin in the first column of the line • No space or tab before or after the semicolon

  10. PHP – strings: Heredoc syntax • Variables are evaluated • Escape sequences are evaluated

  11. PHP – strings: Heredoc • $name = “PHP”; • $version = 4.2; • echo <<<EOTMy name is "$name“\n\n\n\n My version is $versionEOT;

  12. PHP – strings: Heredoc • $str = <<<EODExample of string<BR>spanning multiple lines<BR>using heredoc syntax.EOD;

  13. PHP – back quotes • Can use back quotes to execute UNIX command (same as Perl) • $today = `date`; • $today contains output of UNIX command data • Can also do • echo `date`;

More Related