6

我有一个这样的数组

$data = array(
    "some"   => "163",
    "rand"  => "630",
    "om"    => "43",
    "words" => "924",
    "as"    => "4",
    "keys"  => "54"
);

如何获取与其值相关联的每个集合的键,如下所示:

foreach ($data as $stuff){
  $this->$stuff["key"] = $stuff["value"];
}
4

2 回答 2

16
foreach ($data as $key => $value){
  echo "$key => $value\n";
}
于 2010-09-15T23:03:35.233 回答
5
foreach($data as $key => $value)
{
    // $key and $value variable are available here
    // First iteration values would be: $key = "some" and $value = "163"
}
于 2010-09-15T23:03:59.393 回答