0

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?

2
  • @vivek_23 fix typo, but still have the problem Commented Oct 12, 2019 at 9:35
  • Can you share minimum verifiable example? Use 3v4l.org for demo sharing Commented Oct 12, 2019 at 9:38

4 Answers 4

1

If you want to get key only then use

foreach($tax_input as $key => $tax)
{
  var_dump($key);
}
Sign up to request clarification or add additional context in comments.

3 Comments

@Badrinath generally it's good practice to use builtin functions if available.
Yes, but for @sfarzoso 's understanding this one is the best way.
array_keys($array)
1

use php array_keys() function

print_r(array_keys($tax_input));

Comments

0

try this one.

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

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

Comments

0

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.