Data TypestMyn1 Data Types The type of a variable is not set by the programmer; rather, it is decided at runtime by PHP depending on the context in which.

Slides:



Advertisements
Similar presentations
CERTIFICATION OBJECTIVES Use Class Members Develop Wrapper Code & Autoboxing Code Determine the Effects of Passing Variables into Methods Recognize when.
Advertisements

©2004 Brooks/Cole Chapter 2 Variables, Values and Operations.
Bellevue University CIS 205: Introduction to Programming Using C++ Lecture 3: Primitive Data Types.
1 Chapter 9 - Formatted Input/Output Outline 9.1Introduction 9.2Streams 9.3Formatting Output with printf 9.4Printing Integers 9.5Printing Floating-Point.
1 Chapter 4 Language Fundamentals. 2 Identifiers Program parts such as packages, classes, and class members have names, which are formally known as identifiers.
1 Arrays  Arrays are objects that help us organize large amounts of information  Chapter 8 focuses on: array declaration and use passing arrays and array.
Chapter 9 Formatted Input/Output Acknowledgment The notes are adapted from those provided by Deitel & Associates, Inc. and Pearson Education Inc.
Chapter 6 C Arrays Acknowledgment The notes are adapted from those provided by Deitel & Associates, Inc. and Pearson Education Inc. Arrays are data structures.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Chapter 9 - Formatted Input/Output Outline 9.1Introduction.
Data types and variables
JavaScript, Fourth Edition
Chapter 2 Data Types, Declarations, and Displays
JavaScript, Third Edition
C Formatted Input/Output /* Using Integer Conversion Specifiers */ #include int main ( ) { printf( "%d\n", 455 ); printf( "%i\n", 455 ); printf( "%d\n",
String Escape Sequences
Introduction to Array The fundamental unit of data in any MATLAB program is the array. 1. An array is a collection of data values organized into rows and.
Basic Elements of C++ Chapter 2.
 2007 Pearson Education, Inc. All rights reserved C Formatted Input/Output.
Computer Science 1000 Spreadsheets II Permission to redistribute these slides is strictly prohibited without permission.
Chapter 2 Data Types, Declarations, and Displays.
Objectives You should be able to describe: Data Types
Introduction to Programming Prof. Rommel Anthony Palomino Department of Computer Science and Information Technology Spring 2011.
Chapter 4 – The Building Blocks Data Types Literals Variables Constants.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved Streams Streams –Sequences of characters organized.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Chapter 9 - Formatted Input/Output Outline 9.1Introduction.
Chapter 9 Formatted Input/Output. Objectives In this chapter, you will learn: –To understand input and output streams. –To be able to use all print formatting.
 2005 Pearson Education, Inc. All rights reserved Formatted Output.
Input & Output: Console
Chap 3 – PHP Quick Start COMP RL Professor Mattos.
Copyright © 2012 Pearson Education, Inc. Publishing as Pearson Addison-Wesley C H A P T E R 2 Input, Processing, and Output.
C-Language Keywords(C99)
Input, Output, and Processing
PHP By Sergio Rodriguez By Sergio Rodriguez. PHP G PHP: Hypertext Preprocessor G Scripting language G PHP: Hypertext Preprocessor G Scripting language.
Arrays Module 6. Objectives Nature and purpose of an array Using arrays in Java programs Methods with array parameter Methods that return an array Array.
Lec 6 Data types. Variable: Its data object that is defined and named by the programmer explicitly in a program. Data Types: It’s a class of Dos together.
Knowledge Base C++ #include using std namespace; int main(){} return 0 ; cout
Built-in Data Structures in Python An Introduction.
Copyright © 2012 Pearson Education, Inc. Publishing as Pearson Addison-Wesley C H A P T E R 2 Input, Processing, and Output.
ITM © Port, KazmanVariables - 1 ITM 352 Data types, Variables.
Sys Prog & Scripting - HW Univ1 Systems Programming & Scripting Lecture 16: PHP Types.
Comments in PHP In PHP, we use // to make a singleline comment or /* and */ to make a large comment block. Comment is a part of your PHP code that will.
Python Primer 1: Types and Operators © 2013 Goodrich, Tamassia, Goldwasser1Python Primer.
Data Types Declarations Expressions Data storage C++ Basics.
CSCI 3133 Programming with C Instructor: Bindra Shrestha University of Houston – Clear Lake.
Chapter 4 Literals, Variables and Constants. #Page2 4.1 Literals Any numeric literal starting with 0x specifies that the following is a hexadecimal value.
By Mr. Muhammad Pervez Akhtar
CHAPTER 2 PROBLEM SOLVING USING C++ 1 C++ Programming PEG200/Saidatul Rahah.
 Variables can store data of different types, and different data types can do different things.  PHP supports the following data types:  String  Integer.
Basic Scripting & Variables Yasar Hussain Malik - NISTE.
Types Chapter 2. C++ An Introduction to Computing, 3rd ed. 2 Objectives Observe types provided by C++ Literals of these types Explain syntax rules for.
Arrays Chapter 7. MIS Object Oriented Systems Arrays UTD, SOM 2 Objectives Nature and purpose of an array Using arrays in Java programs Methods.
ITM © Port, KazmanVariables - 1 ITM 352 Data types, Variables Class #4.
_______________________________________________________________________________________________________________ PHP Bible, 2 nd Edition1  Wiley and the.
C++ Array 1. C++ provides a data structure, the array, which stores a fixed-size sequential collection of elements of the same type. An array is used.
Basic Data Types อ. ยืนยง กันทะเนตร คณะเทคโนโลยีสารสนเทศและการสื่อสาร มหาวิทยาลัยพะเยา Chapter 4.
Introduction C# program is collection of classes Classes are collection of methods and some statements That statements contains tokens C# includes five.
CSE 110: Programming Language I Matin Saad Abdullah UB 1222.
1Object-Oriented Program Development Using C++ Built-in Data Types Data type –Range of values –Set of operations on those values Literal: refers to acceptable.
1 ENERGY 211 / CME 211 Lecture 3 September 26, 2008.
28 Formatted Output.
C Formatted Input/Output
Topics Designing a Program Input, Processing, and Output
Wel come.
TMF1414 Introduction to Programming
Introduction to C++ Programming
Introduction to Primitive Data types
Python Primer 1: Types and Operators
Topics Designing a Program Input, Processing, and Output
Topics Designing a Program Input, Processing, and Output
Introduction to Primitive Data types
Presentation transcript:

Data TypestMyn1 Data Types The type of a variable is not set by the programmer; rather, it is decided at runtime by PHP depending on the context in which that variable is used.

Data TypestMyn2 PHP supports eight primitive types. Four scalar types: –boolean –integer –float (floating-point number, aka double) –string Two compound types: –array –object And finally two special types: –resource –NULL

Data TypestMyn3 A boolean expresses a truth value. It can be either TRUE or FALSE. Typically, some kind of operator which returns a boolean value, and the value is passed on to a control structure.

Data TypestMyn4 When converting to boolean, the 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)

Data TypestMyn5

Data TypestMyn6

Data TypestMyn7 An integer is a number of the set Z = {..., -2, -1, 0, 1, 2,...}. Integers can be specified in decimal (base 10), hexadecimal (base 16), or octal (base 8) notation, optionally preceded by a sign (- or +). To use octal notation, precede the number with a 0 (zero). To use hexadecimal notation precede the number with 0x. The size of an integer is platform-dependent, although a maximum value of about two billion is the usual value (that's 32 bits signed). PHP does not support unsigned integers. Integer size can be determined using the constant PHP_INT_SIZE, and maximum value using the constant PHP_INT_MAX. If PHP encounters a number beyond the bounds of the integer type, it will be interpreted as a float instead. Also, an operation which results in a number beyond the bounds of the integer type will return a float instead.

Data TypestMyn8

Data TypestMyn9

Data TypestMyn10 Floating point numbers (also known as "floats", "doubles", or "real numbers") can be specified using any of the following syntaxes: The size of a float is platform-dependent, although a maximum of ~1.8e308 with a precision of roughly 14 decimal digits is a common value.

Data TypestMyn11 A string is series of characters. A string literal can be specified in four different ways: –single quoted –double quoted –heredoc syntax –nowdoc syntax (since PHP 5.3.0) The simplest way to specify a string is to enclose it in single quotes (the character '). To specify a literal single quote, escape it with a backslash (\). To specify a literal backslash before a single quote, or at the end of the string, double it (\\). Note that attempting to escape any other character will print the backslash too.

Data TypestMyn12 Variables and escape sequences for special characters will not be expanded when they occur in single quoted strings.

Data TypestMyn13

Data TypestMyn14

Data TypestMyn15

Data TypestMyn16 If the string is enclosed in double-quotes ("), PHP will interpret more escape sequences for special characters, for example \n, \t, \$, \\ and \” (still some others). As in single quoted strings, escaping any other character (those not in the list which was partially printed above) will result in the backslash being printed too. The most important feature of double-quoted strings is the fact that variable names will be expanded.

Data TypestMyn17

Data TypestMyn18

Data TypestMyn19 When displaying text we have always used echo. There is also another alternative: print. What is the difference between echo and print ? Not much, print is more like a PHP function, so it returns a value, which is always set to 1. For most purposes, echo and print work the same way in PHP, so the one you use is up to you.

Data TypestMyn20 echo — Output one or more strings Description void echo ( string $arg1 [, string $... ] ) Outputs all parameters. echo() is not actually a function (it is a language construct), so you are not required to use parentheses with it. echo() (unlike some other language constructs) does not behave like a function, so it cannot always be used in the context of a function. Additionally, if you want to pass more than one parameter to echo(), the parameters must not be enclosed within parentheses. Parameters arg1 –The parameter to output. Return Values No value is returned.

Data TypestMyn21 print — Output a string Description int print ( string $arg ) Outputs arg. print() is not actually a real function (it is a language construct) so you are not required to use parentheses with its argument list. Parameters arg –The input data. Return Values Returns 1, always.

Data TypestMyn22

Data TypestMyn23

Data TypestMyn24

Data TypestMyn25

Data TypestMyn26

Data TypestMyn27 An array in PHP is actually an ordered map. A map is a type that associates values to keys. This type is optimized for several different uses; it can be treated as an array, list (vector), hash table (an implementation of a map), dictionary, collection, stack, queue, and probably more. As array values can be other arrays, trees and multidimensional arrays are also possible. An array can be created by the array() language construct. It takes as parameters any number of comma- separated key => value pairs.

Data TypestMyn28 array() — Create an array Description array array ([ mixed $... ] )mixed Creates an array. Parameters... –Syntax "index => values", separated by commas, define index and values. index may be of type string or integer. When index is omitted, an integer index is automatically generated, starting at 0. If index is an integer, next generated index will be the biggest integer index + 1. Note that when two identical indexes are defined, the last overwrite the first. –Having a trailing comma after the last defined array entry, while unusual, is a valid syntax. Return Values Returns an array of the parameters. The parameters can be given an index with the => operator.

Data TypestMyn29 A key may be either an integer or a string. If a key is the standard representation of an integer, it will be interpreted as such (i.e. "8" will be interpreted as 8, while "08" will be interpreted as "08"). Floats in key are truncated to integer. The indexed and associative array types are the same type in PHP, which can both contain integer and string indices. A value can be any PHP type. If a key is not specified for a value, the maximum of the integer indices is taken and the new key will be that value plus 1. If a key that already has an assigned value is specified, that value will be overwritten.

Data TypestMyn30

Data TypestMyn31

Data TypestMyn32 The pre element defines preformatted text. The text enclosed in the pre element usually preserves spaces and line breaks. The text renders in a fixed-pitch font.

Data TypestMyn33 print_r() — Prints human-readable information about a variable Description mixed print_r ( mixed $expression [, bool $return= false ] ) print_r() displays information about a variable in a way that's readable by humans. Remember that print_r() will move the array pointer to the end. Use reset() to bring it back to beginning.

Data TypestMyn34 Parameters expression –The expression to be printed. return –If you would like to capture the output of print_r(), use the return parameter. If this parameter is set to TRUE, print_r() will return its output, instead of printing it (which it does by default). Return Values If given a string, integer or float, the value itself will be printed. If given an array, values will be presented in a format that shows keys and elements. Similar notation is used for objects.

Data TypestMyn35 An existing array can be modified by explicitly setting values in it. This is done by assigning values to the array, specifying the key in brackets. The key can also be omitted, resulting in an empty pair of brackets ([]). If $arr doesn't exist yet, it will be created, so this is also an alternative way to create an array. To change a certain value, assign a new value to that element using its key. To remove a key/value pair, call the unset() function on it.

Data TypestMyn36

Data TypestMyn37

Data TypestMyn38 The following example demonstrates how to create an one-dimensional array and how to specify keys for associative array:

Data TypestMyn39

Data TypestMyn40

Data TypestMyn41

Data TypestMyn42