json_encode Or jQuery's getJSON

They both do the same thing, create a JSON object, though one does it on the server end while the other has the browser do all the work.

For returning output, which is better for performance?

I guess this is part of a bigger question, when you have an option of processing output data on the server side or the client side, which is better?

I would imagine for a high traffic website it would be best to push as much of the workload off onto the client side.

I think you have misunderstood what the jQuery.getJSON()[/FONT] method actually does, when you make a request to the server the array you return should already be JSON encoded otherwise your creating a redundant request. If this happens you would be much better off just using the [FONT=courier new][URL=“http://api.jquery.com/jQuery.get/”]jQuery.get() method which allows you to set a 3rd argument as either (text, html, json) etc…

With that said i would recommend you always process the array server side all the time as JSON encoding an array barely uses any memory, no matter how small the array is though i will always process the array server side to avoid creating redundant code.

Thanks for the clarification, and for the informative response to both my questions.

Unless I’m wrong again, it sounds like these two functions are likely both to be used in a single HTTP request and response.

Yes, as your echoing the array back JSON encode it at the same time, see the below example:

$myArray = array('hello', 'there');

exit(json_encode($myArray));