我在php中使用多维数组,我想知道如何获取我在foreach循环中返回的值的“字段名称”。
$_SESSION['filter']['dateCreation'] = 'ASC';
$_SESSION['filter']['client'] = 'test';
print_r($_SESSION['filter']);
foreach ($_SESSION['filter'] as $filter)
{
// how do I echo the name of the field here? Eg. dateCreation
echo $filter;
}
答案 0 :(得分:2)
foreach ($_SESSION['filter'] as $keyname => $filter)
echo "$keyname value is $filter\n";
答案 1 :(得分:1)
foreach ($_SESSION['filter'] as $key => $value) ...
答案 2 :(得分:1)
foreach ($_SESSION['filter'] as $field_name=>$filter)
{
echo $field_name, $filter;
}
答案 3 :(得分:1)
foreach ( $array as $key => value)
{
...
}