ধরুন, আমাদের অবজেক্টটি হলো—
$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