EspañolDeutschFrançaisItalianoPortuguêsРусскийΕλληνικά日本語中文(简体)हिन्दी; हिंदीالعربية
Definir como idioma padrão
Perguntas de PF - Fórum

Seria como tirar uma matriz associativa e obter os valores da chave??

Minha matriz associativa é:

$valores = array ( 1 => "Juan", 3 => "Victor", 7 => "Valeria" );

Si lo recorro usando foreach, na variável $valor se guardan los valores

foreach ( $valores in $valor ) {
   echo $valor;
}

¿Cómo puedo obtener en vez de los valores, las claves de dichos valores? Ou seja, Neste caso, { 1, 3, 7 }

Share on Facebook Tweet about this on Twitter Share on Google+ Pin on Pinterest Share on Reddit Share on VK Share on StumbleUpon Share on Tumblr Share on LinkedIn Email this to someone Print this page
javi_menes Será que perguntou 7 anos
1 Respostas
Melhor resposta

Puedes hacerlo así:

foreach ( $valores as $clave => $valor ) {
echo $clave;
}

Desta forma, en cada iteracción, en la variables $clave y $valor se almacenan sus respectivos valores de clave y valor.

Share on Facebook Tweet about this on Twitter Share on Google+ Pin on Pinterest Share on Reddit Share on VK Share on StumbleUpon Share on Tumblr Share on LinkedIn Email this to someone Print this page
diegodel disse faz 7 anos