PHP入门

来源:互联网 发布:手机安装软件赚钱 编辑:程序博客网 时间:2024/05/22 06:19
2009-09-23 20:38

first.php

<html>

<head>
<title>
This is my first php page   !!!
</title>
</head>

<body>
<?php
//echo 'hello world!!!';
//echo phpinfo();
$foo=25;
$bar=$foo;//定义一个变量,它的值与foo的值相等

$foo=100;
echo "<br>".'$bar='.$bar;//25
$bar=&$foo;//引用一个变量,$foo改变,$bar的值跟着改变。bar相当于foo的一个别名
echo "<br>".'$bar='.$bar;//100
echo '<br><hr></hr>';
function test(){

echo '执行test()后$bar的值为:'.$bar;//什么都没有
}
test();

function test1(){
global $bar;
echo '<br>执行test1()后$bar的值为:'.$bar;//100
}
test1();

function test2($x){
$x=200;
}
test2($bar);
echo '<br>执行test2()后$bar的值为:'.$bar;//100

function test3(&$x){
$x=200;
}
test3($bar);
echo '<br>执行test3()后$bar的值为:'.$bar;//200
echo '<hr></hr>';
$a=array(1=>10,2.5=>3.15,'a'=>'c',"love"=>"d");
var_dump($a);//打印数组详细信息,如数组整体长度和数组内各元素数据类型与长度
echo '<br>';
print_r($a);//打印数组或任何对象类型
echo '<br>取数组中下标为';
echo '<hr></hr>';
class person{

}
$p=new person();//或者写成new person
print_r($p);
echo '<hr></hr>';
$file="D:/myphp/1.txt";
$handle=@fopen($file,"r");
echo $handle;
echo '<hr></hr>';
echo '<b>获取变量类型用gettype(),$bar的类型为:</b>'.gettype($bar);

$m=2;
echo '<br><b>判断变量类型用is_int,is_string,is_float等,判断$bar是否为整型:</b>'.is_int($bar);
$m=(String)$m;
echo '<br><b>$m=2执行$m=(String)$m;后调用is_string($m);的结果:</b>'.is_string($m);

?>

</body>
</html>

页面输出:

$bar=25
$bar=100


执行test()后$bar的值为:
执行test1()后$bar的值为:100
执行test2()后$bar的值为:100
执行test3()后$bar的值为:200


array(4) { [1]=> int(10) [2]=> float(3.15) ["a"]=> string(1) "c" ["love"]=> string(1) "d" }
Array ( [1] => 10 [2] => 3.15 [a] => c [love] => d )
取数组中下标为


person Object ( )


Resource id #3


获取变量类型用gettype(),$bar的类型为:integer
判断变量类型用is_int,is_string,is_float等,判断$bar是否为整型:1
$m=2执行$m=(String)$m;后调用is_string($m);的结果:1

原创粉丝点击