php 基础笔记 variables
/***************************by
garcon1986********************************/
<?php
// variable name is sensitive
$var = "sjg";
$Var = "wl";
echo $var.' loves '.$Var.'<br>';
echo "$var, $Var<p>";
//naming conventions for variables
//$4site = 'not yet'; // invalid; starts with a number
$_4site = 'not yet'; // valid; starts with an underscore
$täyte = 'mansikka'; // valid; '洄 is (Extended) ASCII 228.
echo $_4site.'<br>';
echo $täyte.'<p>';
// pass the address
$ref1 = 'ref1';
$ref2 = &$ref1;
echo $ref1.'<br>'; //ref1
echo $ref2.'<br>'; //ref1
$ref2 = "My name is $ref2";
echo $ref1.'<br>'; //ref1
echo $ref2.'<p>'; //ref1
//$ref2 = &(24*7); //Invalid reference.
function test1()
{
return 25;
}
//$bar = &test(); // Invalid reference.
//global scope ;
$a1 = 1; /* global scope */
function test2()
{
$a1 = 2; // local variable
echo $a1.'<br>'; /* reference to local scope variable */
}
test2();
echo $a1.'<br>'; // global variable
//local scope
$a2 = 3;
$b2 = 4;
function Sum2(){
global $a2, $b2;
$b2 = $a2 + $b2;
}
Sum2();
echo $b2.'<p>';
//static variable
function test3(){
static $a=0;
echo $a;
$a++;
}
test3();
echo '<br>';
test3();
echo '<br>';
test3();
echo '<br>';
test3();
echo '<br>';
test3();
echo '<p>';
//global variable and static variable
function test_global_ref(){
global $obj;
$obj = &new stdClass;
}
function test_global_noref(){
global $obj;
$obj = new stdClass;
}
test_global_ref();
var_dump($obj);
echo '<br>';
test_global_noref();
var_dump($obj);
echo '<p>';
// variable variables
$a3 = 'hello';
$$a3 = 'world';
echo "$a3 ${$a3}"."<br>";
echo "$a3 $hello"."<p>";
?>
相关文档:
练琴的时候把RIFF叫做一个曲子的小片段,那么我自己定义一下程序的RIFF就是一小段程序吧,放一些这几天自己写的,以后也长期更新,作为自己积累和今后编程的参考。
1. 格式化网址,若没有HTTP头则插入HTTP头
<?php
//add http head to url
function AddHttpHead( &$s )
{
$exist = strstr( $s,"http://" ......
<!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; charset=gb2312" />
<title>PHP分页</tit ......
转载自:http://www.gracecode.com/archives/3013/
作者:手气不错
真的是不用不知道,其实我们熟悉的 PHP 还有很多好东西没有发掘。看到这篇文章
,当时就泪奔了好几回,重点推荐下,顺便我自己也做个整理。
sys_getloadavg()
这个函数
返回当前系统的负载均值信息
(当然 Windows 下不适用),详细文档可以翻阅 PH ......
/***************************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);
// =& ......