WWW PHP Comments Literals Identifiers Keywords Variables Constants Data Types Operators & Expressions 2

Similar documents
C/C++语言 - 运算符、表达式和语句

C/C++ - 字符输入输出和字符确认

WWW PHP

3.1 num = 3 ch = 'C' 2

CC213

Fun Time (1) What happens in memory? 1 i n t i ; 2 s h o r t j ; 3 double k ; 4 char c = a ; 5 i = 3; j = 2; 6 k = i j ; H.-T. Lin (NTU CSIE) Referenc

6-1 Table Column Data Type Row Record 1. DBMS 2. DBMS MySQL Microsoft Access SQL Server Oracle 3. ODBC SQL 1. Structured Query Language 2. IBM

C/C++程序设计 - 字符串与格式化输入/输出

CHAPTER VC#

Microsoft PowerPoint - STU_EC_Ch02.ppt

C/C++语言 - C/C++数据

前言 C# C# C# C C# C# C# C# C# microservices C# More Effective C# More Effective C# C# C# C# Effective C# 50 C# C# 7 Effective vii

C/C++ - 文件IO

FY.DOC

Perl

Java

Microsoft Word - 3D手册2.doc

Microsoft PowerPoint - STU_EC_Ch04.ppt

C C

untitled

1 Framework.NET Framework Microsoft Windows.NET Framework.NET Framework NOTE.NET NET Framework.NET Framework 2.0 ( 3 ).NET Framework 2.0.NET F

02

C/C++ 语言 - 循环

数据结构与算法 - Python基础

C++ 程式設計

C

Microsoft PowerPoint - STU_EC_Ch08.ppt

Microsoft Word - 第3章.doc

Important Notice SUNPLUS TECHNOLOGY CO. reserves the right to change this documentation without prior notice. Information provided by SUNPLUS TECHNOLO

Knowledge and its Place in Nature by Hilary Kornblith

目 錄 壹 青 輔 會 結 案 附 件 貳 活 動 計 劃 書 參 執 行 內 容 一 教 學 內 容 二 與 當 地 教 師 教 學 交 流 三 服 務 執 行 進 度 肆 執 行 成 效 一 教 學 課 程 二 與 當 地 教 師 教 學 交 流 三 服 務 滿 意 度 調 查 伍 服 務 檢

1 Project New Project 1 2 Windows 1 3 N C test Windows uv2 KEIL uvision2 1 2 New Project Ateml AT89C AT89C51 3 KEIL Demo C C File

LEETCODE leetcode.com 一 个 在 线 编 程 网 站, 收 集 了 IT 公 司 的 面 试 题, 包 括 算 法, 数 据 库 和 shell 算 法 题 支 持 多 种 语 言, 包 括 C, C++, Java, Python 等 2015 年 3 月 份 加 入 了 R

科学计算的语言-FORTRAN95

( CIP) /. :, ( ) ISBN TP CIP ( 2005) : : : : * : : 174 ( A ) : : ( 023) : ( 023)

untitled

Microsoft Word - ch04三校.doc

Microsoft Word - PHP7Ch01.docx

Microsoft Word - 09.數學 docx

epub 94-3

9, : Java 19., [4 ]. 3 Apla2Java Apla PAR,Apla2Java Apla Java.,Apla,,, 1. 1 Apla Apla A[J ] Get elem (set A) A J A B Intersection(set A,set B) A B A B

CC213

PowerPoint Presentation

新・解きながら学ぶJava

Computer Architecture

Microsoft Word - 把时间当作朋友(2011第3版)3.0.b.06.doc

untitled

, 7, Windows,,,, : ,,,, ;,, ( CIP) /,,. : ;, ( 21 ) ISBN : -. TP CIP ( 2005) 1

Ps22Pdf

Business Objects 5.1 Windows BusinessObjects 1

Microsoft PowerPoint - php6.ppt

新版 明解C++入門編

coverage2.ppt

<4D F736F F F696E74202D20B5DAD2BBD5C228B4F2D3A1B0E6292E BBCE6C8DDC4A3CABD5D>

Simulator By SunLingxi 2003

PowerPoint プレゼンテーション

第5章修改稿

Improved Preimage Attacks on AES-like Hash Functions: Applications to Whirlpool and Grøstl

<4D F736F F D20B2C43032B3B920B8EAAEC6ABACBA41BB50AAEDA5DCA6A12E646F63>

基于UML建模的管理管理信息系统项目案例导航——VB篇

untitled

Microsoft PowerPoint - Model Checking a Lazy Concurrent List-Based Set Algorithm.ppt [Compatibility Mode]

PowerPoint Presentation

untitled

C C C The Most Beautiful Language and Most Dangerous Language in the Programming World! C 2 C C C 4 C Project 30 C Project 3 60 Project 40

untitled

CHAPTER 1

概述

國立中山大學論文典藏.PDF

TC35短信发送程序设计

C

C 1


Microsoft PowerPoint - L17_Inheritance_v4.pptx

Microsoft PowerPoint - ds-1.ppt [兼容模式]

基于ECO的UML模型驱动的数据库应用开发1.doc

RUN_PC連載_8_.doc

2/80 2

Microsoft PowerPoint - C15_LECTURE_NOTE_05.ppt

C/C++ - 函数

Chapter 9: Objects and Classes

C语言的应用.PDF

C/C++ - 字符串与字符串函数

Tel: Fax: TTP-344M/246M /

Microsoft Word - 苹果脚本跟我学.doc

ebook65-5

27 :OPC 45 [4] (Automation Interface Standard), (Costom Interface Standard), OPC 2,,, VB Delphi OPC, OPC C++, OPC OPC OPC, [1] 1 OPC 1.1 OPC OPC(OLE f

06-4.indd

mvc

untitled

Progperl.PDF

Microsoft Word

<4D F736F F D D342DA57CA7DEA447B14D2DA475B57BBB50BADEB27AC3FEB14DA447B8D5C344>

Bourne Shell及shell编程

生死之交

Microsoft Word - SupplyIT manual 3_cn_david.doc

TwinCAT 1. TwinCAT TwinCAT PLC PLC IEC TwinCAT TwinCAT Masc

ebook35-2


投影片 1

Transcription:

WWW PHP 2003 1 Comments Literals Identifiers Keywords Variables Constants Data Types Operators & Expressions 2

Comments PHP Shell Style: # C++ Style: // C Style: /* */ $value = $p * exp($r * $t); # $value = $p * exp($r * $t); // /* */ 3 # (//) # (//) PHP?> <?php $d = 100; # d 100?> <?php echo $d?> 100 /* */ /* */ PHP /* $j = 1; $i = 100; /* */ */ 4

/* */ comment out $i = 100; /* $j = $i + 20; $k = $i * $j; */ $i ++; 5 Literals 2001, 0xFE 3.14, 1.0E-6 Hello, A String, true, false, null 6

Identifiers name PHP 1. _ ASCII 0X7F 0XFF 2. 0 9 7 Keywords PHP PHP if, else, do, true,, $argc, $_POST,, PHP array, echo,, PHP 8

Variables PHP $ $amount $this_is_friday $_here $not valid $3Com $@someplace 9 C/C++ PHP PHP $var = 3; $var = Hello ; $var = array(10, 20, 30); $var = 5; # # # # 10

Constants PHP define() define(name, expression); name expression define(pi, 3.1415); echo PI; # 3.1415 define(message, How are you doing? ); echo MESSAGE; # How are you doing? 11 Data Types PHP boolean integer floating number string array object NULL resource 12

boolean true false if ($isok) { } PHP false false 0 0.0 0 NULL true 13 integer PHP -2,147,483,648 2,147,483,648 2003, -123, +78 0x 0X 0XFF, 0x16, 0xff, -0xABCD 0 0755, -0123 14

floating number PHP C double 15 1.7 10-308 1.7 10 308 3.14, 0.0015, -7.8 0.314E1, 0.314e1, 13.5E-4, -2.1e6 15 string PHP Thanks God, it s Friday escape sequence Hello, world! \\ \ \ 16

\n newline \r carriage return \t horizontal tab \\ backslash \$ dollar sign \{ right brace \} brace \[ right bracket \] bracket \ double quote \ooo ooo 1 3 ASCII \xhh hh ASCII 17 echo Don t stop! ; echo <h1 align=\ center\ > ; echo First line\nsecond line ; echo Ho\x6De ; echo C:\\Windows ; Don t stop <h1 align= center > First line Second line Home C:\Windows $value = 100; echo The value is $value ; The value is 100 echo Don\ t stop! ; echo <h1 align= center > ; echo First line\nsecond line ; echo The value is $value ; echo C:\\Windows ; Don t stop <h1 align= center > First line\nsecond line The value is $value C:\Windows 18

array PHP PHP indexed array 40 25 3.14 Hello 0 1 2 99 indices associative array key keys lastname firstname sex values male 19 $myarray[0] = 40; $myarray[1] = 50; $myarray[3] = 20; $myarray[4] = 10; NULL $myarray 40 50?? 20 10 0 1 2 3 4 $myform[ lastname ] = ; $myform [ firstname ] = ; $myform [ sex ] = male ; keys lastname firstname sex values male $myform 20

PHP array() $myarray = array(40, 50, NULL, 20, 10); # $myarray 40 50 NULL 20 10 0 1 2 3 4 # $myform = array( lastname =>, firstname =>, sex => male ); keys lastname firstname sex $myform values male 21 NULL PHP 1. NULL $var = NULL; # $var 2. 3. unset() unset($var); # $var 22

resource $resourse $resourse = db_connection(); # db_connection() $resourse $resourse db_query($resource, $query); # qb_query() $query 23 $var is_bool($var); is_float($var); is_array($var); is_null($var); is_int($var); is_string($var); is_object($var); is_resource($var); var_dump($var) $var 24

25 Example $a + $b $a - $b $a * $b $a / $b $a % $b -$a Name Addition Subtraction Multiplication Division Modulus negation Result Sum of $a and $b. Difference of $a and $b. Product of $a and $b. Quotient of $a and $b. Remainder of $a divided by $b. Multiply $a by -1 +$a assertion The as $a 26

PHP 5 + 4 # 9 (int) 17 + 3.14 # 20.14 (float) 27 PHP 5 + 3.14 # 8.14 (int) 9 Lives 1 # 8 (int) 3.14 Pies * 2 # 6.28 (float) 1.0E3 Points of Light + 1 # 1001 (float) 28

Example Name Result $a & $b And Bits that are set in both $a and $b are set. $a $b Or Bits that are set in either $a or $b are set. $a ^ $b Xor Bits that are set in $a or $b but not both are set. ~ $a $a << $b $a >> $b Not Shift Shift right Bits that are set in $a are not set, and vice versa. Shift the bits of $a $b steps to the (each step means "multiply by two") Shift the bits of $a $b steps to the right (each step means "divide by two") 29 PHP ~$a $a $a & $b $a $b $a ^ $b $a $b $a $b $a << $b $a >> $b $a $b 30

Assignment Operator Example Result Example Result $a = $b $a is set to be the value of $b $a &= $b $a = ($a & $b) $a += $b $a = ($a + $b) $a = $b $a = ($a $b) $a -= $b $a = ($a - $b) $a ^= $b $a = ($a ^ $b) $a *= $b $a = ($a * $b) $a <<= $b $a = ($a << $b) $a /= $b $a = ($a / $b) $a >>= $b $a = ($a >> $b) $a %= $b $a = ($a % $b) $a.= $str $a = ($a. $str) 31 Example Name Effect ++$a Pre-increment Increments $a by one, then returns $a. $a++ --$a $a-- Post-increment Pre-decrement Post-decrement Returns $a, then increments $a by one. Decrements $a by one, then returns $a. Returns $a, then decrements $a by one. 32

Example $a == $b $a === $b $a!= $b $a <> $b $a!== $b $a < $b $a > $b $a <= $b $a >= $b Name Equal Identical Not equal Not equal Not identical Less than Greater than Less than or equal to Greater than or equal to Result TRUE if $a is equal to $b. TRUE if $a is equal to $b, and they are of the same type. (PHP 4 only) TRUE if $a is not equal to $b. TRUE if $a is not equal to $b. TRUE if $a is not equal to $b, or they are not of the same type. (PHP 4 only) TRUE if $a is strictly less than $b. TRUE if $a is strictly greater than $b. TRUE if $a is less than or equal to $b. TRUE if $a is greater than or equal to $b. 33 == ===!=!== 3.14 == 3.14 # true 3.14 === 3.14 # false 3.14 === 3.14 # true 3.14 == 3.14 Pies # true 3.14 === 3.14 Pies # false 3.14!= 3.14 # false 3.14!== 3.14 # true 3.14!== 3.14 # false 3.14!= 3.14 Pies # false 3.14!== 3.14 Pies # true 3.14 <> 3.14 # false 34

3.14, 20, 1.0e-6,, Hello, 3 books,, 35 Example Name Result $a and $b $a && $b $a or $b $a $b $a xor $b And Or Xor TRUE if both $a and $b are TRUE. TRUE if either $a or $b is TRUE. TRUE if either $a or $b is TRUE, but not both.! $a Not TRUE if $a is not TRUE. 36

Lazy Evaluation PHP Lazy Evaluation 1 == 1 or echo This is skipped true $result = fopen($filename) or exit(); exit() $result = $flag and mysql_connect(); $flag mysql_connect() 37 $string1. $string2 $string1 $string2 $string1.= $string2 $string1 = $string1. $string2; Hello,. world! # Hello, world! The value is. 3 # The value is 3 The value is. 3 # The value is 3 $a = 3.14; The value is. $a # The value is 3.14 $a = It s ; $a.= ok. ; # $a It s ok. 38

Type Casting C/C++ (int) (integer) (float) (real) (bool) (boolean) (string) (array) Integer Floating point Boolean String Array (object) Object 39? : (conditional_expr)? true_expr : false_expr conditional_expr true true_expr false_expr $a = (3 == 3 )? equal : not equal ; # $a = equal $a = (3 === 3 )? equal : not equal ; # $a = not equal 40

Error Control Operator PHP @ /* Intentional file error */ $my_file = @file ('non_existent_file') or die ("Failed opening file: error was '$php_errormsg'"); // this works for any expression, not just functions: $value = @$cache[$key]; // will not issue a notice if the index $key doesn't exist. 41 Execution Operator `external_command` PHP ` external_command WWW Unix $output = `ls -al`; echo "<pre>$output</pre>"; 42

Associativity Operators, or xor and right print = += -= *= /=.= %= &= = ^= ~= <<= >>=? : && ^ & non-associative ==!= ===!== non-associative < <= > >= << >> + -. * / % right! ~ ++ -- (int) (float) (string) (array) (object) @ right non-associative [ new 43 PHP ( ) echo 1 + 2 * 3; # 7 echo (1 + 2) * 3; # 9 echo 1 + (2 + 3) * 4; # 21 associativity right echo 4 2-1; # 1 (not 3) echo (int)(float) 3.14; # 3 echo (float)(int) 3.14; # 3.0 44