【发布时间】:2016-09-19 02:49:16
【问题描述】:
我基本上正在尝试创建一个过滤系统,它从 HTML 表单中的输入中获取数据,然后在 PHP 中使用该数据过滤来自 $profileArray 的现有“配置文件”,输出包含用户输入的数据/变量的任何配置文件(s)。我不知道如何通过我的 filter_array 函数发送用户输入数据,据我所知,这些函数可以使用var_dump 对其进行测试。
作为一个初学者,我无法理解 php.net 中的 $foo 和 $bar 解释,因此非常感谢清晰的解释。
HTML
<html>
<body>
<form action="profileFilter.php" method="POST">
<p>Age: <input type="text" name="ageChoice"></p>
<p>Colour: <input type="text" name="colourChoice"></p>
<input type="submit" name="catQualitiesBtn">
</form>
</body>
</html>
PHP
<?php
$profileArray = array(
array( 'Name' => "Toby",
'Age' => 3,
'Colour' => "Ginger",
),
array( 'Name' => "Cassie",
'Age' => 3,
'Colour' => "Tabby",
),
array( 'Name' => "Lucy",
'Age' => 1,
'Colour' => "Black",
)
);
function get_profile_by_age ($profile, $age){
return array_filter ($profile, function($ageInput) use ($age){
return $ageInput['Age'] === $age;
});
}
function get_profile_by_age ($profile, $colour){
return array_filter ($profile, function($colourInput) use ($colour){
return $colourInput['Colour'] === $colour;
});
}
$ageInput = intval($_POST['ageChoice']);
$colourInput = strval($_POST['colourChoice']);
echo function get_profile_by_age ($ageInput , $age);
echo function get_profile_by_colour ($colourInput , $colour);
?>
【问题讨论】: