PHP DATA TYPES

Views:
 
Category: Education
     
 

Presentation Description

No description available.

Comments

Presentation Transcript

PHP DATA TYPES : 

PHP DATA TYPES Jonathan Pasayan Norman Claridad Juebien Dagcutan A data type is the specific category of information that a variable contains.

Introduction : 

Introduction PHP: Hypertext Preprocessor supports eight Primitive types. Boolean Four Scalar Types: Integer Float(double) String Two compound types: Array Object Two Special Types: Resource NULL Pseudo-Types Also Introduces

Four Scalar Type(scalar=holds only one value at a time) : 

Four Scalar Type(scalar=holds only one value at a time) Boolean Integer Float(Double) String Boolean(“bool”) This is the simplest type. Also known as the logical type and can be either TRUE(1) or FALSE(0). Commonly used in an arguments. The boolean type was introduced in PHP 4. It decides which part of a program should execute and which part should compare data. Example: This is true This is not true

Specify a boolean literal: : 

Specify a boolean literal: To specify a boolean literal, use the keywords TRUE or FALSE. Both are case-insensitive. <?php$foo = True; // assign the value TRUE to $foo?>

<?php// == is an operator which test// equality and returns a boolean// this is not necessary...if ($show_separators == TRUE) {    echo "<hr>\n";}// ...because instead, this can be used:if ($show_separators) {    echo "<hr>\n";}?> : 

<?php// == is an operator which test// equality and returns a boolean// this is not necessary...if ($show_separators == TRUE) {    echo "<hr>\n";}// ...because instead, this can be used:if ($show_separators) {    echo "<hr>\n";}?>

When can Boolean be true or false? : 

When can Boolean be true or false? Following values are considered FALSE: the boolean FALSE itself the integer 0 (zero) the float 0.0 (zero) the empty string, and the string "0" an array with zero elements an object with zero member variables (PHP 4 only) the special type NULL (including unset variables) SimpleXML objects created from empty tags Others values are considered TRUE. $norman=FALSE; $juebien= 0; $fredie=0.0; $jeffrey= “” or “0”

Slide 7: 

Four Scalar Type Boolean Integer Float(Double) String Integers are whole numbers (negative or positive). Can be notated to: Octal(base 8), Hexadecimal(base 16) and Decimal(base 10) Note that: Octal precedes with 0 Hexadecimal precedes with 0x

Integral Notations : 

Integral Notations Decimal Octal Hex Converting between Integer: Convert the number 256 DECIMAL to HEXADECIMAL

Convert 1128 Hexadecimal to Decimal : 

Convert 1128 Hexadecimal to Decimal

Simple way to convert hexadecimal and octal to decimal using PHP : : 

Simple way to convert hexadecimal and octal to decimal using PHP : Hexadecimal 14116 Decimal Octal 2004

Coverting to Integer : 

Coverting to Integer $str is declared a string $num is declared integer with value converted from string $str Integer String to Integer

Slide 12: 

Four Scalar Type Boolean Integer Float(Double) String Float(a.k.a. Double) are numbers with a decimal point(positive or negative), like 1.432 and -1.432 1

Slide 13: 

Review: