PHP入门

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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值