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();
?>