博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
PHP 笔记一(systax/variables/echo/print/Data Type)
阅读量:4452 次
发布时间:2019-06-07

本文共 2715 字,大约阅读时间需要 9 分钟。

PHP stands for "Hypertext Preprocessor" ,it is a server scripting language.

What Can PHP Do?

  • PHP can generate dynamic page content
  • PHP can create, open, read, write, delete, and close files on the server
  • PHP can collect form data
  • PHP can send and receive cookies
  • PHP can add, delete, modify data in your database
  • PHP can be used to control user-access
  • PHP can encrypt data

1> Basic PHP Syntax

1 

2> Comments in PHP

1 

3> Case Sensitivity

In PHP, all keywords (e.g. if, else, while, echo, etc.), classes, functions, and user-defined functions are NOT case-sensitive.

1 
";3 echo "Hello World!
";4 EcHo "Hello World!
";5 ?>

However; all variable names are case-sensitive.

1 
";4 echo "My house is " . $COLOR . "
";5 echo "My boat is " . $coLOR . "
";6 ?>

4> PHP Variables

Rules for PHP 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)

PHP is a Loosely Typed Language

PHP Variables Scope

PHP has three different variable scopes:

  • local
  • global
  • static

PHP also stores all global variables in an array called $GLOBALS[index]. The index holds the name of the variable.

1 

5> PHP echo and print Statements

echo and print are more or less the same. They are both used to output data to the screen.

The differences are small:

  • echo has no return value while print has a return value of 1 so it can be used in expressions.
  • echo can take multiple parameters (although such usage is rare) while print can take one argument.
  • echo is marginally faster than print.

echo Display Text

1 
PHP is Fun!";3 echo "Hello world!
";4 echo "I'm about to learn PHP!
";5 echo "This ", "string ", "was ", "made ", "with multiple parameters.";6 ?>

echo Display Variables

1 
$txt1"; 8 echo "Study PHP at $txt2
"; 9 echo $x + $y;10 ?>

print Display Text

1 
PHP is Fun!";3 print "Hello world!
";4 print "I'm about to learn PHP!";5 ?>

print Display Variables

1 
$txt1"; 8 print "Study PHP at $txt2
"; 9 print $x + $y;10 ?>

6> PHP Data Types

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
  • Array
  • Object
  • NULL
  • Resource

Example

1 

Object Example

1 
model = "VW"; 5 } 6 } 7 8 // create an object 9 $herbie = new Car();10 11 // show object properties12 echo $herbie->model;13 ?>

 

转载于:https://www.cnblogs.com/hzj680539/p/5107848.html

你可能感兴趣的文章
tomcat server.xml配置详解
查看>>
java05
查看>>
前后端通信 (3种方式简单介绍)
查看>>
java条件语句练习题
查看>>
文件操作open,r,w,a三种模式
查看>>
开发工具安装密钥
查看>>
十一周总结学习笔记
查看>>
dubbo控制器xml文件报错
查看>>
extjs 控件属性
查看>>
HDU 6264(思维)
查看>>
延迟、延时、定时调用
查看>>
MongoDB的更新操作符
查看>>
TreeMap的学习
查看>>
【SICP练习】2 练习1.6
查看>>
wireshark基础学习—第一部分wireshark的基础知识
查看>>
JavaScript--DOM总结
查看>>
关于两个服务器数据库之间的数据几种方法实践
查看>>
Laravel LTS 分割 路由文件的最佳方式
查看>>
什么是python?
查看>>
Flat files upload(本地文件数据上载)(二)
查看>>