Variables, Operators and Data Types. By Shyam Gurram.

Slides:



Advertisements
Similar presentations
UFCE8V-20-3 Information Systems Development 3 (SHAPE HK) Lecture 3 PHP (2) : Functions, User Defined Functions & Environment Variables.
Advertisements

Operators and Expressions Operators are symbols that produce a result based on some rules. Examples: +, -, =, > and
Chapter 41 Variables and JSP Control Structures JavaServer Pages By Xue Bai.
Lecture 2 Introduction to C Programming
Data types and variables
JavaScript, Fourth Edition
Chapter 2 Data Types, Declarations, and Displays
JavaScript, Third Edition
Introduction to C Programming
Introduction To C++ Programming 1.0 Basic C++ Program Structure 2.0 Program Control 3.0 Array And Structures 4.0 Function 5.0 Pointer 6.0 Secure Programming.
Basic Elements of C++ Chapter 2.
Php. What is PHP? PHP is an acronym for "PHP Hypertext Preprocessor" PHP is a widely-used, open source scripting language PHP scripts are executed on.
1 Chapter Two Using Data. 2 Objectives Learn about variable types and how to declare variables Learn how to display variable values Learn about the integral.
Chapter 2 Data Types, Declarations, and Displays.
Objectives You should be able to describe: Data Types
Introduction to PHP and Server Side Technology. Slide 2 PHP History Created in 1995 PHP 5.0 is the current version It’s been around since 2004.
Chapter 4 – The Building Blocks Data Types Literals Variables Constants.
Chap 3 – PHP Quick Start COMP RL Professor Mattos.
DEPARTMENT OF COMPUTER SCIENCE & TECHNOLOGY FACULTY OF SCIENCE & TECHNOLOGY UNIVERSITY OF UWA WELLASSA 1 CST 221 OBJECT ORIENTED PROGRAMMING(OOP) ( 2 CREDITS.
2440: 211 Interactive Web Programming Expressions & Operators.
Chapter 3: Data Types and Operators JavaScript - Introductory.
Internet & World Wide Web How to Program, 5/e © by Pearson Education, Inc. All Rights Reserved.
Internet & World Wide Web How to Program, 5/e © by Pearson Education, Inc. All Rights Reserved.
Chapter 3 Processing and Interactive Input. 2 Assignment  The general syntax for an assignment statement is variable = operand; The operand to the right.
Introduction to Java Applications Part II. In this chapter you will learn:  Different data types( Primitive data types).  How to declare variables?
1 Working with Data Types and Operators. 2 Using Variables and Constants The values stored in computer memory are called variables The values, or data,
CSC 330 E-Commerce Teacher Ahmed Mumtaz Mustehsan Ahmed Mumtaz Mustehsan GM-IT CIIT Islamabad GM-IT CIIT Islamabad CIIT Virtual Campus, CIIT COMSATS Institute.
Introduction to PHP A user navigates in her browser to a page that ends with a.php extension The request is sent to a web server, which directs the request.
Open Source Software Unit – 3 Presented By Mr. R.Aravindhan.
Knowledge Base C++ #include using std namespace; int main(){} return 0 ; cout
Variables and ConstantstMyn1 Variables and Constants PHP stands for: ”PHP: Hypertext Preprocessor”, and it is a server-side programming language. Special.
Introduction to C Programming Chapter 2 : Data Input, Processing and Output.
1Computer Sciences Department Princess Nourah bint Abdulrahman University.
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.
Operators Precedence - Operators with the highest precedence will be executed first. Page 54 of the book and Appendix B list C's operator precedence. Parenthesis.
VARIABLES, CONSTANTS, OPERATORS ANS EXPRESSION
Server-Side Scripting with PHP ISYS 475. PHP Manual Website
הרצאה 4. עיבוד של דף אינטרנט דינמי מתוך Murach’s PHP and MySQL by Joel Murach and Ray Harris.  דף אינטרנט דינמי משתנה עפ " י הרצת קוד על השרת, יכול להשתנות.
CHAPTER 6 Introduction to PHP5 Part I อ. ยืนยง กันทะเนตร คณะเทคโนโลยีสารสนเทศและการสื่อสาร มหาวิทยาลัยพะเยา 1.
Creating PHP Pages Chapter 6 PHP Variables, Constants and Operators.
Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Fluency with Information Technology Third Edition by Lawrence Snyder Chapter.
Part:2.  Keywords are words with special meaning in JavaScript  Keyword var ◦ Used to declare the names of variables ◦ A variable is a location in the.
PHP Programming with MySQL Slide 3-1 CHAPTER 3 Working with Data Types and Operators.
Open Source Server Side Scripting ECA 236 Open Source Server Side Scripting PHP Basics.
FP512 WEB PROGRAMMING 1 PREPARED BY: PN. NUR SYUHADA BINTI MOHAMAD.
Chapter 3 Introduction to PHP. Incorporating PHP Within HTML By default, PHP documents end with the extension.php files ending with.htm or.html to also.
 Variables can store data of different types, and different data types can do different things.  PHP supports the following data types:  String  Integer.
0 Chap.2. Types, Operators, and Expressions 2.1Variable Names 2.2Data Types and Sizes 2.3Constants 2.4Declarations 2.5Arithmetic Operators 2.6Relational.
Session 2: PHP Language Basics iNET Academy Open Source Web Development.
ITM © Port, KazmanVariables - 1 ITM 352 Data types, Variables Class #4.
C Language 1 Program Looping. C Language2 Topics Program looping Program looping Relational operators / expressions Relational operators / expressions.
Dr. Abdullah Almutairi Spring PHP is a server scripting language, and a powerful tool for making dynamic and interactive Web pages. PHP is a widely-used,
PHP Tutorial. What is PHP PHP is a server scripting language, and a powerful tool for making dynamic and interactive Web pages.
Introduction to PHP and MySQL (Creating Database-Driven Websites)
1 Lecture 2 - Introduction to C Programming Outline 2.1Introduction 2.2A Simple C Program: Printing a Line of Text 2.3Another Simple C Program: Adding.
PHP using MySQL Database for Web Development (part II)
Chapter Topics The Basics of a C++ Program Data Types
BASIC ELEMENTS OF A COMPUTER PROGRAM
Basic Elements of C++.
Web Programming– UFCFB Lecture 19-20
PHP Introduction.
Basic Elements of C++ Chapter 2.
Character Set The character set of C represents alphabet, digit or any symbol used to represent information. Types Character Set Uppercase Alphabets A,
Chapter 8 JavaScript: Control Statements, Part 2
PHP.
PHP an introduction.
Algoritma & Pemrograman 1
SEEM 4540 Tutorial 4 Basic PHP based on w3Schools
Contact PSK Technologies Pvt. Ltd IT Company Address - Plot No-780, Near Durga Temple, Katol Road Chaoni, Nagpur-13.
Presentation transcript:

Variables, Operators and Data Types. By Shyam Gurram

Variables Variables: There are certain rules for variables A variable starts with the $ sign, followed by the name of the variable A variable name must start with a letter or the underscore character A variable name cannot start with a number A variable name can only contain alpha-numeric characters and underscores (A-z, 0- 9, and _ ) Variable names are case-sensitive ($age and $AGE are two different variables)

User Defined Variables. PHP variables names must start with an underscore or an alphabetical character. Underscores start most predefined PHP variables, so starting user-defined variables with an alphabetical character is a good idea. PHP variables were once always assigned by value or by reference. You define a variable in PHP by prefacing the variable name with a $ symbol. Variables may be scalar or compound. The difference between scalar and compound variables is scalar variables can hold one thing at a time, where as compound variables may hold more than one thing.

When you define and assign a value to a variable in one step, this is called declaring a variable. We can assign variables by reference to other variables. Assignment by value is done using a binary assignment operator, which is the equal (=) symbol between two operands. The left operand is the target variable, and the right operand is a source value or reference. Assignment statements are typically terminated by a semicolon to complete the expression. We can assign by a reference using a combination of an assignment operator and ampersand (&) preceding the source variable name like &$variableName.

Operators Operators are used to perform operations on variables and values. PHP divides the operators in the following groups: Arithmetic operators. Assignment operators. Comparison operators. Increment/Decrement operators. Logical operators. String operators. Array operators.

PHP Arithmetic Operators The PHP arithmetic operators are used with numeric values to perform common arithmetical operations, such as addition, subtraction, multiplication etc.

PHP Assignment Operators AssignmentSame as...Description x = y The left operand gets set to the value of the expression on the right x += yx = x + yAddition x -= yx = x - ySubtraction x *= yx = x * yMultiplication x /= yx = x / yDivision x %= yx = x % yModulus The PHP assignment operators are used with numeric values to write a value to a variable. The basic assignment operator in PHP is "=". It means that the left operand gets set to the value of the assignment expression on the right.

PHP Comparison Operators OperatorNameExampleResult ==Equal$x == $yReturns true if $x is equal to $y ===Identical$x === $yReturns true if $x is equal to $y, and they are of the same type !=Not equal$x != $yReturns true if $x is not equal to $y <>Not equal$x <> $yReturns true if $x is not equal to $y !==Not identical$x !== $yReturns true if $x is not equal to $y, or they are not of the same type >Greater than$x > $yReturns true if $x is greater than $y <Less than$x < $yReturns true if $x is less than $y >=Greater than or equal to $x >= $yReturns true if $x is greater than or equal to $y <=Less than or equal to$x <= $yReturns true if $x is less than or equal to $y The PHP comparison operators are used to compare two values (number or string).

PHP Increment / Decrement Operators OperatorNameDescription ++$xPre-incrementIncrements $x by one, then returns $x $x++Post-incrementReturns $x, then increments $x by one --$xPre-decrementDecrements $x by one, then returns $x $x--Post-decrementReturns $x, then decrements $x by one The PHP increment operators are used to increment a variable's value. The PHP decrement operators are used to decrement a variable's value.

PHP Logical Operators OperatorNameExampleResult andAnd$x and $yTrue if both $x and $y are true orOr$x or $yTrue if either $x or $y is true xorXor$x xor $yTrue if either $x or $y is true, but not both &&And$x && $yTrue if both $x and $y are true ||Or$x || $yTrue if either $x or $y is true !Not!$xTrue if $x is not true The PHP logical operators are used to combine conditional statements.

PHP String Operators OperatorNameExampleResult.Concatenation$txt1. $txt2Concatenation of $txt1 and $txt2.=Concatenation assignment $txt1.= $txt2Appends $txt2 to $txt1 PHP has two operators that are specially designed for strings.

PHP Array Operators OperatorNameExampleResult +Union$x + $yUnion of $x and $y ==Equality$x == $yReturns true if $x and $y have the same key/value pairs ===Identity$x === $yReturns true if $x and $y have the same key/value pairs in the same order and of the same types !=Inequality$x != $yReturns true if $x is not equal to $y <>Inequality$x <> $yReturns true if $x is not equal to $y !==Non-identity$x !== $yReturns true if $x is not identical to $y The PHP array operators are used to compare arrays.

PHP Datatypes Variables can store data of different types, and different data types can do different things. PHP supports the following data types: String Integer Float (floating point numbers - also called double) Boolean

PHP String "; echo $y; ?> A string is a sequence of characters, like "Hello world!". A string can be any text inside quotes. You can use single or double quotes:

PHP Integer An integer is a whole number (without decimals). It is a number between -2,147,483,648 and +2,147,483,647. Rules for integers: An integer must have at least one digit (0-9) An integer cannot contain comma or blanks An integer must not have a decimal point An integer can be either positive or negative Integers can be specified in three formats: decimal (10- based), hexadecimal (16-based - prefixed with 0x) or octal (8-based - prefixed with 0)

PHP Float A float (floating point number) is a number with a decimal point or a number in exponential form. In the following example $x is a float. The PHP var_dump() function returns the data type and value

PHP Boolean $x = true; $y = false; A Boolean represents two possible states: TRUE or FALSE. Booleans are often used in conditional testing. You will learn more about conditional testing in a later chapter of this tutorial.

PHP Global Variables. Global variables are of two types. One is Environmental level and the other is Script level variables. Environmental level variables are available any where in your PHP progra,. Script level variables are available only externally to functions unless you pass them to a function as an actual parameter.

PHP Predefined Variables. PHP predefined variables are also known as super global variables which means that they are always accessible, regardless of scope - and you can access them from any function, class or file without having to do anything special. The PHP superglobal variables are: $GLOBALS $_SERVER $_REQUEST $_POST $_GET $_FILES $_ENV $_COOKIE $_SESSION

Predefined Variables. Variable NameDescription $GLOBALSThe variable contains a reference to every variable with in the global scope of the script. The keys for these values are the names of the global variables. $_COOKIEThe variable contains all HTTP cookies. It replaces the deprecated $$HTTP_COOKIE_VARS array. $_ENVThe variable contains all inherited environment variables or those directly set within the script. It replaces the deprecated $HTTP_ENV_VARS array. $_GETThe variable contains all the URL query string values. It replaces the $HTTP_GET_VARS array.

Predefined Variables. Variable NameDescription $_SERVERThe variables contains variables set by the execution environment of the web server and current running scripts. It replaces the deprecated $HTTP_SERVER_VARS array. $_SESSIONThe variable contains variables bound to the current session. It replaces the deprecated $HTTP_SESSION_VARS array. $_FILESThe variable contains all variables provided by HTTP POST file uploads. It replaces the deprecated $HTTP_POST_FILES array. $_POSTThe variable contains all variables provided by HTTP POST it replaces the deprecated $HTTP_POST_VARS array.

Predefined Variables. $_REQUEST: The variable contains all variables provided by GET, POST, and COOKIE inputs. The order of the variable is set by the PHP variable order configuration parameter. The values in this variable are a security risk because it makes a man-in-the-middle attack more likely, since $_GET is insecure. You should use the $_POST in lieu of the $_REQUEST predefined variable.