如何获取数组中键的值? 我的数组就像:
$array = array(
array(key1 => "value1", key2 => "value2", key3 => "value3"),
array(key1 => "value1", key2 => "value2", key3 => "value3"),
array(key1 => "value1", key2 => "value2", key3 => "value3"),
array(key1 => "value1", key2 => "value2", key3 => "value3")
);
foreach($array as $row) {
$key1 = $row['key1'];
$key2 = $row['key2'];
$key3 = $row['key3'];
}
//所以应该可以写例如echo $ ke1,然后得到out value1或echo $ key2并得到输出:value 2等等......
这怎么可能?希望有人理解我:)。
最好的问候
答案 0 :(得分:0)
这是你要找的吗?
foreach($array as $row) {
foreach($row as $key => $value) {
// first iteration, $key == key1, $value = 'value1'
}
}