简单php笔记(一)

1.判断类型:


<?php

	$testing;
	$testing = 1;
	echo "testing is int?".is_int($testing);
	echo "<br/>";
	
	$testing = 0.5;
	echo "testing is float?".is_float($testing);
	echo "<br/>";
	
	$testing = 'abc';
	echo "testing is string?".is_string($testing);
	echo "<br/>";
	
	$testing = true;
	echo "testing is boolean?".is_bool($testing);
	echo "<br/>";
	
	$testing = array('a','b');
	echo "testing is int?".is_array($testing);
	echo "<br/>";
	
	
	echo "testing is numeric?".is_numeric($testing);
	echo "<br/>";
	
	
	echo "testing is array?".is_array($testing);
	echo "<br/>";
	
	echo "testing is null?".is_null($testing);
	echo "<br/>";
	
?>


2.settype():


<?php
        $undefined = 3.14;
        echo "is undefined a doubel?".is_double($undefined);
        echo "<br/>";
        
        settype($undefined, 'string');
        echo "is undefined a string?".is_string($undefined);
        
        echo $undefined;
        echo "<br/>"
        
        settype($undefined, 'integer');
        echo "is undefined a integer?".is_int($undefined);
        
        echo $undefined;
        echo "<br/>"
        
        settype($undefined, 'bool');
        echo "is undefined a bool?".is_bool($undefined);
        
        echo $undefined;
        echo "<br/>"
?>

此外还有gettype()很简单了。


3.常量:


<?php
        define ("pi",3.1415);
        echo "pi is ".pi;

?>

4.if:

<?php
        $mood = "happy";
        if ($mood == "happy") {
                echo "$mood every.";
        }

?>

for 语句类似C


5.两个for:

<?php

echo "<table style=\"border: 1px solid black;\">\n";
for ($y = 1; $y <=12 ; $y++) {
        echo "<tr>\n";
        for ($x = 1; $x <= 12; $x++) {
                echo "<td style=\"border: 1px solid #000; width: 25px; padding: 4px;
                text-align:center;\">";
                echo ($x*$y);
                echo "</td>";
        }
        echo "</tr> \n";
}
echo "</table>";
?>


6.嵌入js代码:


<?php
   echo "
   <script language =\"JavaScript\" type = \"text/javascript\">

alert(\"hello world!\");

</script>
";

?>


7.strtoupper:


<?php
        $hello = "hello world!";
        echo (strtoupper($hello));
?>


8.引用全局变量:


<?php

        $out = 1;
        function h() {
                global $out;
                echo ($out);
        }
        
        h();

?>



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值