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

在函數內聲明全局變量

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

問題描述

我有兩個 PHP 文件.首先,我根據 $_GET 值設置了一個 cookie,然后調用一個函數,然后將該值發送到另一個文件.這是我在 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"]);

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

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.

我遇到的問題是,當 processJoin.php 中的 grabReferral() 函數被調用時,$referralID 變量是沒有在全球范圍內定義 - processJoin.php 中的其他函數似乎無法訪問它以發送到其他文件/進程.

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 中試過這個:

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

someOtherFunction() {
   sendValue($ref_id);
}

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

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?

推薦答案

你也必須在第二個函數中定義全局變量..

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);
}

菲利克斯

這篇關于在函數內聲明全局變量的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

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

相關文檔推薦

Joining 2 tables in SELECT(MYSQL/PHP)(在 SELECT(MYSQL/PHP) 中加入 2 個表)
How to make lt;option selected=quot;selectedquot;gt; set by MySQL and PHP?(如何使lt;option selected=“selectedgt;由 MySQL 和 PHP 設置?)
Auto populate a select box using an array in PHP(使用 PHP 中的數組自動填充選擇框)
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 產生 JSON_ERROR_UTF8)
MySQL ORDER BY rand(), name ASC(MySQL ORDER BY rand(),名稱 ASC)
主站蜘蛛池模板: 久久久www成人免费无遮挡大片 | 成人中文字幕av | 中文字幕在线观看www | 欧美日韩久久精品 | 黄色大片免费观看 | 国产精品久久久久一区二区三区 | 精品久久国产 | 一区二区在线 | 超碰av人人| 一级做a爰片久久毛片 | 日本成人中文字幕 | av香蕉 | 欧美精品91 | 欧美久久久久久久久中文字幕 | 99久久99| 久草网址| 欧美一级三级 | 99久久亚洲 | a级片网站| 国产精品网页 | 国产在线精品一区二区 | 久久国产欧美日韩精品 | 最新av在线播放 | 国产精品久久久久久久久久三级 | 亚洲成人蜜桃 | 国产高清视频在线播放 | 国产精品日日夜夜 | 欧美日韩一区不卡 | 亚洲欧美国产毛片在线 | 男人的天堂视频网站 | 久久网一区二区 | 亚洲精品黑人 | 欧美日韩中文字幕在线 | 日韩精品视频网 | 午夜视频一区二区 | 伊色综合久久之综合久久 | 自拍偷拍欧美 | 成人综合一区二区 | av在线成人| 国产网站在线免费观看 | 欧美在线一区二区视频 |