[英]Trying to pass an array outside the scope into a function for echo'ing
大家好,我的程序員們,
我有一個問題(除了不夠了解之外),我需要知道如何在一個函數中將一個數組從作用域外部傳遞回內部,然后再回顯特定的數組索引。
我四處搜尋,試圖尋找解決方案,並向其他程序員尋求幫助,但到目前為止沒有任何效果。
在包含文件中,我正在創建數組:
$errmsg[0] = 'the message is too short, please enter more than 10 charaters.';
$errmsg[1] = 'the message is too long, please enter less than 1000 charaters.';
然后,我繼續對數組進行序列化以使其存儲。
$e = serialize($errmsg);
然后在另一個包含文件中,我創建了函數。
function contact($e) {
echo unserialize($errmsg[0]);
}
最后,在主index.php文件中,我回調該函數。
contact($e);
現在,這當然是行不通的,如果有任何一種靈魂能夠將我帶入正確的軌道,甚至給我解決此問題的解決方案,我將非常有幫助。
如果您需要我的進一步信息,請說。
ps:我現在已經完成了當天的工作,所以直到格林尼治標准時間今晚晚些時候我的答復才開始。
function contact() {
global $e;
$unserialize = unserialize($e);
echo $unserialize[0];
}
contact();
更好的是:
$errmsg[0] = '...'; $errmsg[1] = '...';
$e = serialize($errmsg);
function concact($e) {
$array = unserialize($e);
echo $array[0];
}
// now maybe: contact($e);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.