tags:

views:

113

answers:

4

Hi,

I'm using a multi dimensional array in php, I would like to know how to get the "field name" of the value I'm returning in my foreach loop.

$_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;
}
+2  A: 
foreach ($_SESSION['filter'] as $keyname => $filter)
echo "$keyname value is $filter\n";
Havenard
perfect thanks :)
mnml
+1  A: 
foreach ($_SESSION['filter'] as $key => $value) ...
Marko
+1  A: 

foreach ($_SESSION['filter'] as $field_name=>$filter) { echo $field_name, $filter; }

Meep3D
+1  A: 
foreach ( $array as $key => value)
{
    ...
}

Php documentation.

zzandy