For one, what's the point of having $ary at all? Why not just use $POST? Even if you had some reason for duplicating the information (e.g. code you haven't shown us), you could still reduce this:
$ary = array();
if($_POST['submit']) {
foreach ($_POST as $key => $value){
$ary[$key] = $value };
}
down to this:
if($_POST['submit']) {
$ary = $_POST;
Next, I'm not sure what your question is. You echo the JSON encoded string by... well, by [man]echo[/man]'ing (or [man]print[/man]'ing) it.