কম্পিউটার টিউটোরিয়াল

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

  1. PHP-এ date_timezone_set() ফাংশন

  2. PHP-এ date_modify() ফাংশন

  3. PHP-এ method_exists() ফাংশন

  4. PHP-এ get_object_vars() ফাংশন