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