PHP从对象打印键?
假设以下是我们的对象-
$employeeDetails = (object) [
'firstName' => 'John',
'lastName' => 'Doe',
'countryName' => 'US'
];我们想要以下输出,即仅键-
firstName lastName countryName
要仅显示对象中的键,请在PHP中使用array_keys()。
示例
<!DOCTYPE html> <html> <body> <?php $employeeDetails = (object) [ 'firstName' => 'John', 'lastName' => 'Doe', 'countryName' => 'US' ]; $allKeysOfEmployee = array_keys((array)$employeeDetails); echo "All Keys are as follows=","<br>"; foreach($allKeysOfEmployee as &$tempKey) echo $tempKey,"<br>"; ?> </body> </html>
输出结果
All Keys are as follows= firstName lastName countryName
热门推荐
10 新年门口花束祝福语简短
11 盘锦结婚祝福语大全简短
12 父母生日祝福语 简短独特
13 家庭恩爱祝福语简短英文
14 高考俄语祝福语大全简短
15 虎年祝福语 诗句唯美简短
16 生日婚礼祝福语简短精辟
17 虎年喝酒拜年祝福语简短
18 教师闺蜜祝福语简短