PHP数组键值

时间:2010-09-15 23:01:33

标签: php arrays foreach key array-key

我有像这样的数组

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

如何将每个组的键相关联的相关联:

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

2 个答案:

答案 0 :(得分:16)

foreach ($data as $key => $value){
  echo "$key => $value\n";
}

答案 1 :(得分:5)

foreach($data as $key => $value)
{
    // $key and $value variable are available here
    // First iteration values would be: $key = "some" and $value = "163"
}