So, this works:
<?php
$value = ($_POST['x']) ? $_POST['x'] : $y[0];
$output = '<input type="text" name="field1" value="'.$value.'">';
?>
But how to make it work in this case:
<?php
$output = '<input type="text" name="field1" value="'.$($_POST['x']) ? $_POST['x'] : $y[0];.'">';
?>
Just remove the first dollar, that does not belong there, wrap it into braces and remove the semicolon: