Parse error: syntax error, unexpected '=' (T_DOUBLE_ARROW), expecting ',' or ')' in ... on line 2

1

I have literally 2 hours looking for a solution to this error (not to mention the constant disconnections of my FTP client online).

Code:

<?php
$error = array(result => "error", msg => "Alias not specified", url => "https://mc-pe.us/$alias");
$error = json_encode($error);
echo $error;
?>
    
asked by José Hernandez 21.04.2017 в 21:09
source

1 answer

1

It may be because the keys of the array must also be between quotes when they are strings.

This

<?php
$error = array(result => "error", msg => "Alias not specified", url => "https://mc-pe.us/$alias");
$error = json_encode($error);
echo $error;
?>

Like this

<?php
$error = array("result" => "error", "msg" => "Alias not specified", "url" => "https://mc-pe.us/$alias");
$error = json_encode($error);
echo $error;
?>

I just run the example and it works correctly.

Result:

{"result":"error","msg":"Alias not specified","url":"https:\/\/mc-pe.us\/"}
    
answered by 21.04.2017 в 21:15