PHP数组回显我可以访问的javascript数组?

I have a php array called $user.

At the minute I am getting the variables across to javascript by manually adding them like so.

var username = ' . $user['username'] . ';

And so on is there a way I can make php echo a javascript array that I can access?

You're looking for json_encode

PHP:

$json_user = json_encode($user);

JavaScript:

var user = JSON.parse('<?php echo $json_user; ?>');

That's untested code but the idea behind it is sound

Have you tried json_encode ?

<?php echo json_encode ( $array ); ?>

See the documentation here.