sfarzoso
sfarzoso

Reputation: 1600

Cannot get array key name

I'm trying to get the array key name of the following:

[tax_input] => Array
(
    [property-category] => Array
        (
            [1] => 4
            [2] => 8
        )

    [property-action] => Array
        (
            [1] => 9
        )
)

so I'm iterating it as:

foreach($tax_input as $key => $tax)
{
    var_dump($tax_input[$key]);
}

but this return an empty string, what I did wrong?

Upvotes: 0

Views: 67

Answers (4)

LF-DevJourney
LF-DevJourney

Reputation: 28529

You should just echo $key instead of $tax_input[$key]

Upvotes: 0

Umer Abbas
Umer Abbas

Reputation: 1876

use php array_keys() function

print_r(array_keys($tax_input));

Upvotes: 1

Badrinath
Badrinath

Reputation: 491

If you want to get key only then use

foreach($tax_input as $key => $tax)
{
  var_dump($key);
}

Upvotes: 1

V. Prince
V. Prince

Reputation: 130

try this one.

foreach($tax_input as $k => $v)
{
    foreach( $v as $vk => $vv ){

      var_dump( '<pre>',$vv );
    }  
}

Upvotes: 0

Related Questions