简体   繁体   中英

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

I am trying to create an array by using xml file. but when i run the code in server (php version 5.3.24) am getting an error. But tihis is working perfectly in localhost (php version 5.3.5)

Parse error: syntax error, unexpected '[' in /home/content/61/10253461/html/crm/xmas/src.php on line 28

the 28th line is $allowed[$i]=(int)$a->attributes()[1]; in the following code

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

please specify any solution.

Change it to:

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

Function array deferencing is available only from PHP 5.4.0

So on your scenario do like this...

Instead of

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

Do like

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

Source

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM