久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

在函數(shù)內(nèi)聲明全局變量

Declaring a global variable inside a function(在函數(shù)內(nèi)聲明全局變量)
本文介紹了在函數(shù)內(nèi)聲明全局變量的處理方法,對大家解決問題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!

問題描述

我有兩個(gè) PHP 文件.首先,我根據(jù) $_GET 值設(shè)置了一個(gè) cookie,然后調(diào)用一個(gè)函數(shù),然后將該值發(fā)送到另一個(gè)文件.這是我在 join.php 中使用的一些代碼:

I have two PHP files. In the first I set a cookie based on a $_GET value, and then call a function which then sends this value on to the other file. This is some code which I'm using in join.php:

include('inc/processJoin.php');
setcookie("site_Referral", $_GET['rid'], time()+10000);
$joinProc = new processJoin();
$joinProc->grabReferral($_COOKIE["site_Referral"]);

然后另一個(gè)文件 (processJoin.php) 會將此值(以及其他)發(fā)送到其他文件,這些文件將處理數(shù)據(jù)并將其插入到數(shù)據(jù)庫中.

The other file (processJoin.php) will then send this value (among others) to further files which will process and insert the data into the database.

我遇到的問題是,當(dāng) processJoin.php 中的 grabReferral() 函數(shù)被調(diào)用時(shí),$referralID 變量是沒有在全球范圍內(nèi)定義 - processJoin.php 中的其他函數(shù)似乎無法訪問它以發(fā)送到其他文件/進(jìn)程.

The problem I'm having is that when the grabReferral() function in processJoin.php is called, the $referralID variable isn't being defined on a global scale - other functions in processJoin.php can't seem to access it to send to other files/processes.

我在 processJoin.php 中試過這個(gè):

grabReferral($rid) {
   global $ref_id;
   $ref_id = $rid;
}

someOtherFunction() {
   sendValue($ref_id);
}

但是 someOtherFunction 似乎無法訪問或使用 $ref_id 值.我也試過使用 define() 無濟(jì)于事.我做錯(cuò)了什么?

But the someOtherFunction can't seem to access or use the $ref_id value. I've also tried using define() to no avail. What am I doing wrong?

推薦答案

你也必須在第二個(gè)函數(shù)中定義全局變量..

you have to define the global var in the second function as well..

// global scope
$ref_id = 1;

grabReferral($rid){
   global $ref_id;
   $ref_id = $rid;
}

someOtherFunction(){
    global $ref_id;
    sendValue($ref_id);
}

菲利克斯

這篇關(guān)于在函數(shù)內(nèi)聲明全局變量的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請聯(lián)系我們刪除處理,感謝您的支持!

相關(guān)文檔推薦

Joining 2 tables in SELECT(MYSQL/PHP)(在 SELECT(MYSQL/PHP) 中加入 2 個(gè)表)
How to make lt;option selected=quot;selectedquot;gt; set by MySQL and PHP?(如何使lt;option selected=“selectedgt;由 MySQL 和 PHP 設(shè)置?)
Auto populate a select box using an array in PHP(使用 PHP 中的數(shù)組自動填充選擇框)
PHP SQL SELECT where like search item with multiple words(PHP SQL SELECT where like search item with multiple words)
json_encode produce JSON_ERROR_UTF8 from MSSQL-SELECT(json_encode 從 MSSQL-SELECT 產(chǎn)生 JSON_ERROR_UTF8)
MySQL ORDER BY rand(), name ASC(MySQL ORDER BY rand(),名稱 ASC)
主站蜘蛛池模板: 亚洲精品福利在线 | 亚洲第一天堂 | 欧美久久久久久久久 | 久久99精品久久久久 | 色天堂影院 | 国产成人免费视频网站视频社区 | 中文字幕第49页 | 精品国产欧美 | 国产高清一区二区三区 | 久久精品国产99国产精品 | 中文字幕久久精品 | 日韩一区中文字幕 | 国产成人精品a视频一区www | 在线中文字幕日韩 | 91欧美激情一区二区三区成人 | 成人欧美一区二区三区黑人孕妇 | 久久久久久国产精品 | 91av视频在线播放 | 欧美二区三区 | 久久91av | 日韩在线视频观看 | 在线观看亚 | 欧美性影院 | 日韩理论电影在线观看 | 久久99精品久久久久蜜桃tv | 美女一区二区在线观看 | 黑人巨大精品欧美一区二区一视频 | 99re99 | 亚洲日韩中文字幕一区 | 中文字幕一区二区三区四区五区 | 亚洲成人免费在线观看 | 国产成人一区二区三区 | 成人国产免费视频 | 美国一级毛片a | 国产成人小视频 | 亚洲精品1 | 日本一区二区三区免费观看 | 欧美精品一区二区三区四区五区 | 亚洲高清视频一区二区 | 亚洲黄色网址视频 | 国产精品18久久久久久白浆动漫 |