EspañolDeutschFrançaisItalianoPortuguêsРусскийΕλληνικά日本語中文(简体)हिन्दी; हिंदीالعربية
设置为默认语言
PF 问题 - 论坛

如何遍历关联数组和获取键的值?

我的关联数组是:

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

如果走他使用 foreach, 在变量中 $valor 这些值存储

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

如何才能获得而不是值, 这些值的键? 即, 在这种情况下, { 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 preguntó 我们的一日三餐 7 年
1 答案
最佳答案

您可以这样做:

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

以这种方式, 在每一个互动, 在变量 $clave 和 $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 说的得 7 年