PHPÓïÑÔÖÐglobalºÍ$GLOBALS[]µÄ·ÖÎö
<pre>
PHP´úÂë
<?php
// Àý×Ó1
function test_global() {
global $var1, $var2;
$var2 =& $var1;
}
function test_globals() {
$GLOBALS['var3'] =& $GLOBALS['var1'];
}
$var1 = 5;
$var2 = $var3 = 0;
test_global();
print $var2 ."\n";
test_globals();
print $var3 ."\n";
?>
Ö´Ðнá¹ûΪ:
0
5
Ôõô»áÕâÑùÄØ?²»Ó¦¸ÃÊÇ2¸ö5Âð?Ôõô»á³öÏÖ1¸ö0ºÍ1¸ö5ÄØ?
¶÷,ÎÒÃDZ£ÁôÒÔÉÏÎÊÌâ,ÉîÈë·ÖÎö$GLOBALSºÍglobalµÄÔÀí!
ÎÒÃǶ¼ÖªµÀ±äÁ¿ÆäʵÊÇÏàÓ¦ÎïÀíÄÚ´æÔÚ´úÂëÖеÄ"´úºÅ",¼ÙÉèÎÒÃÇÉÏÃæÉùÃ÷µÄ3¸ö±äÁ¿·ÖÅäµÄÄÚ´æÈçÏÂͼ±íʾ:
ÒýÓÃphpÊÖ²áµÄ$GLOBALSµÄ½âÊÍ:
Global ±äÁ¿£º$GLOBALS
×¢Òâ: $GLOBALS ÔÚ PHP 3.0.0 ¼°ÒÔºó°æ±¾ÖÐÊÊÓá£
ÓÉËùÓÐÒѶ¨ÒåÈ«¾Ö±äÁ¿×é³ÉµÄÊý×é¡£±äÁ¿Ãû¾ÍÊǸÃÊý×éµÄË÷Òý¡£
ÕâÊÇÒ»¸ö“superglobal”£¬»òÕß¿ÉÒÔÃèÊöΪ×Ô¶¯È«¾Ö±äÁ¿¡£
Ò²¾ÍÊÇ˵ÉÏÃæ´úÂëÖеÄ$var1ºÍ$GLOBALS['var1']ÊÇÖ¸µÄͬһ±äÁ¿£¬¶ø²»ÊÇ2¸ö²»Í¬µÄ±äÁ¿£¡
ÏÂÃæÀ´·ÖÎöglobalµ½µ××öÁËʲô£¿
ÎÒÃǶ¼ÖªµÀphpÖеĺ¯ÊýËù²úÉúµÄ±äÁ¿¶¼ÊǺ¯ÊýµÄ˽ÓбäÁ¿£¬ÄÇôglobal¹Ø¼ü×Ö²úÉúµÄ±äÁ¿Ò²¿Ï¶¨ÌÓ²»³öÕâ¸ö¹æÔò£¬ÎªÊ²Ã´Õâô˵ÄØ£¬¿´ÏÂÃæµÄ´úÂ룺
PHP´úÂë
<?php
// Àý×Ó2
function test() {
global $a;
unset($a);
}
$a = 1;
test();
print $a;
?>
¸´ÖÆ´úÂë
Ö´Ðнá¹ûΪ£º
1
Ϊʲô»áÊä³ö1ÄØ£¿²»ÊÇÒѾ°Ñ$a¸øunsetÁËÂð£¿unsetʧÁéÁË£¿phpµÄbug£¿
¶¼²»ÊÇ£¬ÆäʵunsetÆð×÷ÓÃÁË£¬ÊÇ°Ñtestº¯ÊýÖеÄ$a¸øunsetµôÁË£¬¿ÉÒÔÔÚº¯ÊýºóÃæ¼ÓÈë
print $a;
¸´ÖÆ´úÂë
À´²âÊÔ£¡Ò²¾ÍÊÇ˵global²úÉúÁËtestº¯ÊýÍⲿ$aµÄ±ðÃû±äÁ¿“$a”,ΪÁ˺ÍÍâÃæµÄ$aÇø±ð£¬ÎÒ°ÑËü³ÉΪ--test->$a,ÄÇôÀý×Ó1Ò²ÕâôÃüÃûµÄ»°£¬¿ÉµÃ
Ïà¹ØÎĵµ£º
ÏÖÔÚÓкܶàµÄrss¶©ÔÄ£¬ÎÒÃÇÖ±½Ó¿ÉÒÔ¶©Ôĵ½ÓÊÏä¡£¼ÈȻѧÁËPHP£¬ÄÇôÓÐûÓÐÒ»ÖÖ·½·¨¿ÉÒÔÖ±½Ó½«rssµÄÐÂÎÅÐÅÏ¢ÏÔʾÔÚ×Ô¼ºµÄÍøÒ³ÉÏÄØ£¿Óеģ¬±ØÐëµÄ£¬ÏÂÃæ¾ÍÊÇÕâ¸örss½Å±¾£º
<?php
//RSSÔ´µØÖ·ÁбíÊý×é
$rssfeed = array("http://blog.csdn.net/heavenopener/category/668064.aspx/rss");
for($i=0;$i<sizeof($rssfee ......
²©¿Í£ºWordPress
WordPressÊÇʹÓÃPHP¿ª·¢µÄÖøÃû²©¿Íƽ̨£¬Ãâ·Ñ¿ªÔ´£¬¹¦ÄÜÇ¿´ó£¬²»½ö½öÓÃÓÚ²©¿Í´î½¨£¬»¹¿ÉÒԹ㷺ӦÓÃÓÚ¸÷ÀàÍøÂçÐÅÏ¢·¢²¼Æ½Ì¨¡£
ÂÛ̳£ºphpBB
phpBBÊÇÒ»Öֹ㷺Á÷ÐеĿªÔ´ÂÛ̳Èí¼þ£¬¾ßÓÐÒ×ÓÚʹÓõĹÜÀíÃæ°åºÍÓѺõÄÓû§°²×°½çÃ棬¿ÉÒÔÇáËɵØÔÚÊý·ÖÖÓÄÚ½¨Á¢ÆðÒ»¸öÂÛ̳£¬¹¦ÄÜÉϾßÓкܸߵĿÉÅäÖÃÐÔ£¬Äܹ»ÍêÈ«¶¨Ö ......
Í·²¿µ÷ÓÃ
<?
require('conn.php');
$sql1="select id from news";
$query1=mysql_query($sql1,$conn);
$sun_num=mysql_num_rows($query1);
$gs=20;
$page_num=ceil($sun_num/$gs);
include("../subpage.php");
//´«¹ýÀ´µÄÒ³Êý²ÎÊý
$PB_page=$_GET['PB_page'];
if ($PB_page==1 or empty($PB_page)){
$ ......
×÷Õß: laruence(http://www.laruence.com
)
±¾ÎĵØÖ·: http://www.laruence.com/2010/05/04/1450.html
תÔØÇë×¢Ã÷³ö´¦
ÔÚ´óÐ͵ÄWebÏîÄ¿ÖÐ, include_pathÊÇÒ»¸öÄ£¿é»¯Éè¼ÆµÄ¸ù±¾Öеĸù±¾(µ±È»,ÏÖÔÚÒ²Óкܶà»ùÓÚautoloadµÄÉè¼Æ,
Õâ¸ö²»Ó°Ïì±¾ÎĵÄ̽ÌÖ), µ«ÊÇÕýÊÇÒòΪinclude_path, ¾³£»áÈÃÎÒÃÇÓöµ½Ò»Ð©ÒòΪûÓÐÕÒµ½Õ ......
ÎÄ/Fenying
¡¡¡¡ÀýÈçÓг£ÓÃʱ¼ä¸ñʽ yyyy-mm-dd HH:ii:ss£¬ÈçºÎת»»³ÉPHPÖÐdateº¯Êý¿ÉʹÓõÄʱ¼ä¸ñʽÄØ£¿
¡¡¡¡Ê¹Óà PHPTimeFormatfromCommon() ¿ÉÒÔ°ÑͨÓÃʱ¼ä¸ñʽת»»³ÉPHPʱ¼ä¸ñʽ
¡¡¡¡¡¡¡¡PHPTimeFormatfromCommon('yyyy-mm-dd HH:ii:ss') => 'Y-m-d H:i:s'
¡¡¡¡Ê¹Óà PHPTimeFormatToCommon() ¿ÉÒÔ° ......