php - 语法错误,意外的 T_DOUBLE_ARROW [英] php - syntax error, unexpected T_DOUBLE_ARROW
本文介绍了php - 语法错误,意外的 T_DOUBLE_ARROW的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我怎样才能摆脱这个错误??
how i can rid of this error??
Parse error: syntax error, unexpected T_DOUBLE_ARROW in /var/www/core/restvt.api.php on line 35
PHP 代码:
$datax = Array();
foreach ($inis as $key => $data){
if ($data=="mem"){
$str = number_format($ARRAY[(array_search($data.':',$ARRAY)+2)]/1024,0,',','.')." MB [ ".number_format(($ARRAY[(array_search($data.':',$ARRAY)+2)]/$ARRAY[(array_search($data.':',$ARRAY)+1)])*100,0,',','.')." % ]";
array_push($datax, "mem"=>$str); //error here, why?
}else{
array_push($datax,$data=>$ARRAY[(array_search($data.':',$ARRAY)+1)]);
}
}
$jsonr = json_encode($datax);
非常感谢您的帮助...
thx alot for your help...
推荐答案
我讨厌看到人们使用 array_push - 我知道这是合法的.在这种情况下,您不能推送 key =>;value
到您的数组,只需执行以下操作:
I hate seeing people use array_push - I know it's legal. In this case, you can't push a key => value
to your array, just do this instead:
$datax['mem'] = $str;
手册:http://php.net/manual/en/function.数组push.php
编辑
如果您坚持使用 array_push
类型的方法,则需要使用新的键值对创建一个新数组,然后使用 array_merge
加入它们:
If you insist on using the array_push
type method, you'll need to create a new array with your new key value pair then use array_merge
to join them:
$new_data = array('mem' => $str);
$datax = array_merge($datax, $new_data);
这篇关于php - 语法错误,意外的 T_DOUBLE_ARROW的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文