Variables Variables are used to store data or information.

Slides:



Advertisements
Similar presentations
 Variables  What are they?  Declaring and initializing variables  Common uses for variables  Variables you get “for free” in Processing ▪ Aka: Built-in.
Advertisements

CIS 234: Using Data in Java Thanks to Dr. Ralph D. Westfall.
The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL Adrian Ilie COMP 14 Introduction to Programming Adrian Ilie June 27, 2005.
Javascript II Expressions and Data Types. 2 JavaScript Review programs executed by the web browser programs embedded in a web page using the script element.
JavaScript, Fourth Edition
JavaScript, Third Edition
1 CS428 Web Engineering Lecture 19 Data Types (PHP - II)
110-D1 Variables, Constants and Calculations(1) Chapter 3: we are familiar with VB IDE (building a form…) to make our applications more powerful, we need.
The Data Element. 2 Data type: A description of the set of values and the basic set of operations that can be applied to values of the type. Strong typing:
Chapter 4 – The Building Blocks Data Types Literals Variables Constants.
The Data Element. 2 Data type: A description of the set of values and the basic set of operations that can be applied to values of the type. Strong typing:
2440: 211 Interactive Web Programming Expressions & Operators.
Java Data Types. Primitive Data Types Java has 8 primitive data types: – char: used to store a single character eg. G – boolean: used to store true or.
CSE 1301 Lecture 2 Data Types Figures from Lewis, “C# Software Solutions”, Addison Wesley Richard Gesick.
TUTORIAL 10: PROGRAMMING WITH JAVASCRIPT Session 2: What is JavaScript?
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,
Primitive Variables.
1Computer Sciences Department Princess Nourah bint Abdulrahman University.
Course Title: Object Oriented Programming with C++ instructor ADEEL ANJUM Chapter No: 03 Conditional statement 1 BY ADEEL ANJUM (MSc-cs, CCNA,WEB DEVELOPER)
ITM © Port, KazmanVariables - 1 ITM 352 Data types, Variables.
1 homework Due today: hw #1 (mailing list printout) readings to date: chapter 1 and chapter read appendix B (3 pages on DOS) and and.
Java Programming, Second Edition Chapter Two Using Data Within a Program.
Creating PHP Pages Chapter 6 PHP Variables, Constants and Operators.
PHP Programming with MySQL Slide 3-1 CHAPTER 3 Working with Data Types and Operators.
Variables and Strings. Variables  When we are writing programs, we will frequently have to remember a value for later use  We will want to give this.
Values, Types, and Variables. Values Data Information Numbers Text Pretty much anything.
 Variables can store data of different types, and different data types can do different things.  PHP supports the following data types:  String  Integer.
DATA TYPES, VARIABLES AND CONSTANTS. LEARNING OBJECTIVES  Be able to identify and explain the difference between data and information  Be able to identify,
ITM © Port, KazmanVariables - 1 ITM 352 Data types, Variables Class #4.
Chapter 4: Variables, Constants, and Arithmetic Operators Introduction to Programming with C++ Fourth Edition.
Expressions and Data Types Professor Robin Burke.
1 Agenda  Unit 7: Introduction to Programming Using JavaScript T. Jumana Abu Shmais – AOU - Riyadh.
Data Types Mr Tottman Link. Data Types Programs need to use data for calculations and for output to various devices The best programs will always use.
Chapter 2 Variables and Constants. Objectives Explain the different integer variable types used in C++. Declare, name, and initialize variables. Use character.
PHP using MySQL Database for Web Development (part II)
CST 1101 Problem Solving Using Computers
ITM 352 Data types, Variables
BASIC ELEMENTS OF A COMPUTER PROGRAM
Documentation Need to have documentation in all programs
Web Technologies PHP 5 Basic Language.
Overview: Programming Concepts
Data Types, Identifiers, and Expressions
PHP (PHP: Hypertext Preprocessor)
Scope, Objects, Strings, Numbers
Web Programming– UFCFB Lecture 19-20
Server-Side Application and Data Management IT IS 3105 (Spring 2010)
JavaScript.
Variables ,Data Types and Constants
Computers & Programming Languages
Numbers.
PHP.
T. Jumana Abu Shmais – AOU - Riyadh
C++ Data Types Data Type
Chapter 2: Java Fundamentals
JavaScript What is JavaScript? What can JavaScript do?
Variables Kevin Harville.
CHAPTER FOUR VARIABLES AND CONSTANTS
JavaScript What is JavaScript? What can JavaScript do?
Variables In today’s lesson we will look at: what a variable is
The Data Element.
Variables Here we go.
Javascript Chapter 19 and 20 5/3/2019.
PHP an introduction.
The Data Element.
An Introduction to Programming
C Programming Lecture-3 Keywords, Datatypes, Constants & Variables
Variables and Constants
Programming Fundamental-1
Presentation transcript:

Variables Variables are used to store data or information. Think of variables as containers that you can put things in. The data stored in a variable is called its value. The value of a variable can be changed. In php (and other programming languages) we often need a place to store values which can later be used by a script or program.

Naming Variables Variables always start with $ Var name cannot start with a number - Start Var name with a letter or underscore, then use any alphanumeric character $foo1 or $_foo1 NOT $1foo Case sensitive $foo is different than $Foo Use names that are descriptive, such as count or speed, not c or s.

Assigning Variables Use the assignment operator = $name = "Rasheed"; // quotes for text or string variables $age = 23; // no quotes for numbers echo "$name is $age"; // Rasheed is 23 echo '$name is $age'; // $name is $age

Example <?php $baskets = 6; $eggsInBasket = 10; $total = $baskets * $eggsInBasket; echo "There are $total eggs"; ?> // There are 60 eggs

Example <?php $a = "eggs"; $b = "doughnuts"; $a = $b; echo $a; ?> // doughnuts

Variable Types String – A string is any group of characters, such as "The quick brown fox jumped over the lazy dog" or "five" or "5" or "Barack Obama" or "aacd". Strings are enclosed in quotation (" ") marks. $animal = "brown fox"; $name = "Rasheed";

Variable Types Integer – Integers are whole numbers, positive or negative, such as 5, -5, 100, 323 $dogs = 10; // Integer $dogs = "10"; // String $foo = 5 + 10; // 15 $pets = $dogs + 5; // 15

Variable Types php is a loosely-typed language, meaning the variable type doesn’t have to be declared. php can decide the type for you, depending on the context, e.g. $dogs = "10"; // string value $animals = 5 + $dogs; // 15 (evaluates as integer)

Variable Types Floats – Floats hold fractional numbers, such as 4.2 or 1.000001 Warning – floating point calculations may not always be accurate, because the binary, base 2 program calculator cannot accurately represent some fractional numbers Avoid comparing float numbers if possible

Variable Types Boolean – Two possible values, true or false $foo = true;

Variable Types Arrays Null Objects Resources We’ll say more about these types later.

isset() function The built-in isset() function returns true if a variable has been set, false if not $foo = 33; if (isset($foo)) { echo '$foo is set'; } // $foo is set

Constants A constant is a special kind of variable that never changes. Use the define() function with two parameters: define("secondsPerMinute", 60); echo secondsPerMinute; // 60

Expressions An expression is anything that has a value. $a = 5 function foo() { return 5; //returns a value of 5 }