0
I have the following array:
Array
(
[CPF_CNPJ] => Array
(
)
[TIPO] => Array
(
)
[NOME] => Array
(
)
)
I know that key(array)
me returns the current key NAME in a loop, but would like to get the key index and not the name.
Example
[CPF_CNPJ] = 0
[TIPO] = 1
[NOME] = 2
I’ll have to make one foreach
for that reason?
I did not see in the PHP manual a proper function for this.
um, I came to see this function, actually it numbers the indices, but actually I wanted to take the number Indice without having to extend the routine too much, it would be like this: $Indice = $meuarray["CPF_CNPJ"]. Itemindex, in Delphi for example we can do Number = Minhalista("field"). Itemindex;
– Marcelo
@Marcelo, I understand exactly, but that I know and from what I have seen now that you told me this: https://www.google.pt/search?client=ubuntu&channel=fs&q=get+numeric+index+of+ass+array&ie=utf-8&oe=utf-8&gfe_rd=cr&ei=OfihV-_jFuas8weX3JOQDg#Channel=fs&q=get+Numeric+index+of+assciative+array+php, seems to make all use of these functions, I believe that in php the best way is so and there is no back to give
– Miguel
@Marcelo Just do it like this:
$indice = array_search('CPF_CNPJ', array_keys($meuArray));
– stderr
Exact as @zekk said and as it is at the end of the answer is also just a line
– Miguel
That’s really it, inattention on my part.
– Marcelo
It’s okay @Marcelo. I’m glad you decided
– Miguel