我有下面的数组如何在循环中获取密钥名称?
$value = stdClass Object ( [autoincrement_id] => 1 [ID] => 1 [State] => Gujarat [Country] => India [Company] => Company1 [rowid] => 1 )
echo $value->State; // I Get Gujarat
但我如何获得动态的密钥名称,我有循环,我不知道我的密钥名称。我可以在循环中写什么,所以我在循环中得到关键名称?
echo $value->[????] // Which i write here to i get value of state?
答案 0 :(得分:2)
您可以使用foreach:
foreach ($values as $key => $val) {
// similar results
echo $values->{$key};
echo $val;
}