珀耳塞福建 发表于 2017-3-28 10:21:59

php 基础笔记

  /***************************bygarcon1986********************************/
  <?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>'; //ref1echo $ref2.'<br>'; //ref1$ref2 = "My name is $ref2";echo $ref1.'<br>'; //ref1echo $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 variableecho $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 variablefunction 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 variablefunction 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>";?>
页: [1]
查看完整版本: php 基础笔记