簡體   English   中英

填充php數組變量不適用於godaddy服務器(php版本5.3.24)在localhost中完美運行

[英]populating php array variable is not working in godaddy server(php version 5.3.24) works perfectly in localhost

我正在嘗試使用xml文件創建一個數組。 但是當我在服務器(php版本5.3.24)中運行代碼時出現錯誤。 但是這在localhost中完美運行(php版本5.3.5)

解析錯誤:語法錯誤,第28行/home/content/61/10253461/html/crm/xmas/src.php中的意外'['

第28行是$ allowed [$ i] =(int)$ a-> attributes()[1]; 在以下代碼中

function parcexml(){
$xml=simplexml_load_file("emaillist.xml");
$allowed=array();
$fname=array();
$femail=array();
$f1=array();
$f2=array();
 $i=0;
  foreach($xml->email as $a) {
    $allowed[$i]=(int)$a->attributes()[1];
    $fname[$i]=$a->attributes()[0];
    $femail[$i]=$xml->children()[$i];
    $i++;
}
}

請指明任何解決方案。

將其更改為:

function parcexml(){
$xml=simplexml_load_file("emaillist.xml");
$allowed=array();
$fname=array();
$femail=array();
$f1=array();
$f2=array();
 $i=0;
  foreach($xml->email as $a) {
    $temp=(int)$a->attributes();
    $allowed[$i]=$temp[1];
    $fname[$i]=$temp[0];
    $temp=$xml->children();
    $femail[$i]=$temp[$i];
    $i++;
}
}

函數數組引用僅在PHP 5.4.0中可用

所以在你的場景中這樣做......

代替

$fname[$i]=$a->attributes()[0];

喜歡

$v = $a->attributes();
$fname[$i] = $v[0];

Source

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM