Q:

Getting array to .ajax on success

I'm trying to return data as an array to my .ajax function on success so I can do do multiple things, but I can't get to work for anything except a single value.  Like return $foo.  But when I return $array, the page never loads up.

A:

You would have to serialize your data into a string. My preference is JSON, so if your PHP version is >= 5.2.0, you'll most likely have access to a json_encode function. This will turn the PHP object into a JSON string. If you don't have access to json_encode, you can use the PECL JSON package.
Looking at the way you reference your ".ajax" function, I am assuming jQuery. So as long as you set the content type to 'json', the JSON response will result in a native JavaScript object. For example,
PHP,
return json_encode(array(1, 2, 3));

JavaScript,
$.ajax({
    ...
    contentType: 'json',
    success: function(response) {
    for (var i = 0; i < response.length; i++) {
        alert(response[i]);
    }
});

This code should proceed to alert 1, 2, and then 3.
I haven't verified the code, but the essential parts are all there. A note to have though, a normal indexed array is turned into a JavaScript list while an associative array will be turned into a JavaScript object.

