Php - 如何return foreach 输入的结果?

Php - How to return the result of foreach input?

我有一个表单用于多个输入条目。

我想遍历它以使用 foreach 函数获取数据并 return 结果。

但不知为何一直失败,因为 $_POST

<?php
$age = array(
    "Peter"=> '35f',
    "Ben"=> '37f', 
    "Joe"=> '43f'
);

foreach( $age as $x => $x_value ) {
    (isset($_POST['$x_value'])) ? $y = $_POST['$x_value'] : '';

    echo "Key=" . $x . ", Value=" . $x_value . ", Input=" . $y;
    echo "\r\n";
}
?>

形式

<form action="" method="post">
    <input name="35f" value="6d583"/>
    <input name="37f" value="2ds43"/>
    <input name="43f" value="5533d"/>
    <input name="submit" value="submit"/>
</form>

预期结果:

Key=Peter, Value=35f, Input=6d583
Key=Ben, Value=37f, Input=2ds43
Key=Joe, Value=43f, Input=5533d

这里不需要单引号:

$y = isset($_POST[$x_value]) ? $_POST[$x_value] : '';

你必须在没有 '' 的括号内使用 $_value 因为它是一个变量而不是字符串

<?php (isset($_POST[$x_value])) ? $y = $_POST[$x_value] : '';