您的位置:首页 > 编程语言 > PHP开发

php tutorial Constant,Variables and data types

2013-03-06 18:22 417 查看
<?php
echo "filename:phptutorial2.php"."<br/>";
echo "2.tutorial:php Constant,Variables and data types"."<br/>";
echo "--------------------------------------------------------------------"."<br/>";
/*file :phptutorial2.php
  title :php Constant,Variables and data types
  date :03/05/2013  
  tool :wamp+notepad++
  author:chinayaosir
  blog :http://blog.csdn.net/chinayaosir
*/
/*
1.PHP常量是为了方便符号便于阅读,大小写不敏感!
常量定义语法:
define(常量名,常量值);
code:
define("thead_begin",1);
define("thead_work",2);
define("thead_sleep",3);
define("thead_end",4);
2.php变量以$为前缀,以字母/下划线开头+任意字符
网页全局引用变量
$_GET[]从浏览器接收的GET变量数组
$_POST[]从浏览器接收的POST变量数组
$_COOKIE[]从浏览器接收的cookie变量数组
$_ENV[]从浏览器接收的环境变量数组
$_SERVER[]从浏览器接收的服务器变量数组
变量定义语法:
<$变量名> [数据类型值];
code:
$name="computer";
$maxrow=48;
3.PHP数据类型:
null:空值
boolean:布称值
integer:整数
float:小数
string:字符串
array:数组
class:类
*/

/*
*/
$bnull;
//boolean Variables
$bfind=FALSE;
$bfalg=TRUE;
//integer Variables
$iminus  =-1235;
$ipositive =369;
//float Variables
$fminus =-36542.2354;
$fpositive=54652.965;
//string Variables
$schar="a";
$sstring="hellow php";
//class Variables
class cperson{
 public function setName($name){$this->name=$name;}
 public function getName(){return $this->name;}
 private $name;
};
$person1=new cperson();
$person1->setName("netboy yao");
//basic datatype test
echo "<br/>php datatype define and test<br/>";
echo "null    datatype bnull:".$bnull."<br/>";
echo "boolean datatype bfind:".$bfind."<br/>";
echo "boolean datatype bfalg:".$bfalg."<br/>";
echo "integer datatype iminus:".$iminus."<br/>";
echo "integer datatype ipositive:".$ipositive."<br/>";
echo "float   datatype fminus:".$fminus."<br/>";
echo "float   datatype fpositive:".$fpositive."<br/>";
echo "string  datatype schar:".$schar."<br/>";
echo "string  datatype sstring:".$sstring."<br/>";
//array test
$sarr=array("apple","orange","banana");
$farr=array(12.3,22.5,63.0,2.2);
echo "<br/>array datatype foreach show:<br/>";
foreach($farr as $fi){ echo "$fi\n";}
echo "<br/>array datatype list()+earch() show:<br/>";
reset($sarr);
while(list($key,$val)=each($sarr)){ echo "#$key=$val\n";}
//class test
echo "<br/>class datatype show:<br/>";
echo "person1->getName()=".$person1->getName();

/*
code export values on wamp
filename:phptutorial2.php
2.tutorial:Constant,Variables and data types
--------------------------------------------------------------------
null datatype bnull:
boolean datatype bfind:
boolean datatype bfalg:1
integer datatype iminus:-1235
integer datatype ipositive:369
float datatype fminus:-36542.2354
float datatype fpositive:54652.965
string datatype schar:a
string datatype sstring:hellow php
array datatype foreach show:
12.3 22.5 63 2.2
array datatype list()+earch() show:
#0=apple #1=orange #2=banana
class datatype show:
person1->getName()=netboy yao
*/
?>
 
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: