// get user information from a database $db = new mysqli('localhost', 'username', 'password', 'database_name'); $user_id = 1; // assume the user ID is 1 $query = "SELECT * FROM users WHERE id = $user_id"; $result = mysqli_query($db, $query); $user_info = mysqli_fetch_assoc($result); // display the user information echo "Name: " . $user_info['name'] . "
"; echo "Email: " . $user_info['email'] . "
"; echo "Age: " . $user_info['age'] . "
";
// get user information from an API $user_id = 1; // assume the user ID is 1 $url = "https://example.com/api/users/$user_id"; $response = file_get_contents($url); $user_info = json_decode($response, true); // display the user information echo "Name: " . $user_info['name'] . "In this example, we use the `getInfo()` method to retrieve user information from an API. We assume that the API returns user information in JSON format. We use the `file_get_contents()` function to retrieve the JSON response from the API. We then decode the JSON response as an associative array using `json_decode()`. Finally, we display the user information on the page. Package/library: none (built-in PHP functions)
"; echo "Email: " . $user_info['email'] . "
"; echo "Age: " . $user_info['age'] . "
";