Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/arrays/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
填充php数组变量在godaddy服务器(php版本5.3.24)中不起作用,在localhost中效果很好_Php_Arrays - Fatal编程技术网

填充php数组变量在godaddy服务器(php版本5.3.24)中不起作用,在localhost中效果很好

填充php数组变量在godaddy服务器(php版本5.3.24)中不起作用,在localhost中效果很好,php,arrays,Php,Arrays,我正在尝试使用xml文件创建一个数组。但是当我在服务器(php版本5.3.24)中运行代码时,我得到了一个错误。但是tihis在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=simplex

我正在尝试使用xml文件创建一个数组。但是当我在服务器(php版本5.3.24)中运行代码时,我得到了一个错误。但是tihis在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++;
}
}
请指定任何解决方案。

函数数组延迟仅在PHP 5.4.0中可用 所以在你的场景中,像这样做

而不是

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

$v = $a->attributes();
$fname[$i] = $v[0];
将其更改为:

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

您好,谢谢。这也在服务器上工作。但我不知道为什么我的代码在本地服务器上工作,而不是在在线服务器上。