Andi Doank Andi Doank - 6 months ago 74
PHP Question

php - syntax error, unexpected 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 Code :

$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?

$jsonr = json_encode($datax);

thx alot for your help...


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;



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);