php 基础笔记 functions
/***************************by
garcon1986********************************/
<?php
//example1
$makefoo = true;
bar();
if($makefoo){
function foo(){
echo "doesn't exist.<br>";
}
}
if($makefoo)foo();
function bar(){
echo "exist<br>";
}
//example2
function sjg(){
function wl(){
echo 'must call sjg() before wl()!<br>';
}
}
sjg();
wl();
//wl();
//sjg();
//example3 - 递归
$a = 10;
function recursion($a){
if($a <= 20){
echo "$a\n";
recursion($a+1);
}
}
recursion($a);
echo "<br>";
//example4 - 向函数传递数组
$input1=array('hi','ni','hao','ya');
function record($input1){
echo $input1[0],$input1[1],$input1[2];
}
record($input1);
//pass the function's parameter by reference
function add_some_extra(&$string){
$string .= 'wl wo ai ni.';
}
$str1 = 'wo xiang shuo,';
add_some_extra($str1);
echo $str1.'<br>'; //output: wo xiang shuo, wl wo ai ni.
//default parameter 默认参数
function makecoffee($category = "cappuccino"){
//return "makeing a cup of $category.\n";
echo "making a cup of $category";
}
echo makecoffee().'<br>';
echo makecoffee("espresso").'<br>';
// add one more parameter
function makeyogurt($type = "acidophilus", $flavour)
{
return "making a bowl of $type and $flavour\n".'<br>';
//return "Makin a bowl of $flavour\n";
}
echo makeyogurt("","raspberry"); // won't work as expected
//echo makeyogurt();
function makeyogurt2($flavour,$type = "acidophilus")
{
//return "making a bowl of $type and $flavour\n".'<br>';
return "Makin a bowl of $flavour $type\n";
}
echo makeyogurt2("raspberry").'<br>'; // will work as expected
//return 示例
function square($num){
return $num * $num;
}
echo square(4).'<p>';
function small_numbers(){
return array(0,1,2);
}
list($ze
相关文档:
Google为全球主要城市提供了统一的天气预报数据存储格式,那就是XML。所有的开发者都可以利用自己喜欢的语言来解析XML获取所需城市的天气预报,本文将介绍利用PHP来获取我所在城市济南的天气预报。
原文见本人网站【PHP探路者】
原文链接:
PHP5 读取Google 天气预报XML API ......
php:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charse ......
apache的源码安装
将压缩包解压之后进入相应的目录
./configure \ #--------------------预编译命令
"--prefix=/usr/local/apache" \ #--------------------安装路径为“/usr/local/apache”
"--with-included-apr" \
"--enable-so" \ #--------------------开启相应的扩展模块 ......
/***************************by
garcon1986********************************/
<?php
//if 语句
$a = $b = 3;
if($a = $b)
print "a is equal to b<br>";
//else 语句
if($a < $b){
print "a is smaller than b";
} else {
print "a is not smaller than b<br> ......
/***************************by
garcon1986********************************/
<?php
// -> 是指对象的方法或者属性
class Cart{
public function add_item($a,$b){
echo $a+$b.'<br>';
}
}
//$cart = new Cart; 两句意义相同
$cart = new Cart();
$cart->add_item("10", 1);
// =& ......