Content · Programming · PHP

PHP cosh() Function: Usage and Examples

Learn how PHP cosh works with practical examples, important behavior, relevant alternatives and common mistakes.

1 views Published Oct 16, 2026 Updated Oct 16, 2026

Calculates the hyperbolic cosine of a number.

What Is cosh() in PHP?

Calculates the hyperbolic cosine of a number.

Its syntax is:

cosh(float $num): float

Parameters:

  • $num — Accepted as float; required argument.

Return type: float. Input values are in the real-number domain; large values may overflow to INF. Do not confuse cosh() with cos().

Availability: Core PHP.

Example 1: Basic Usage

<?php

echo cosh(0);

Output:

1

Input values are in the real-number domain; large values may overflow to INF. Do not confuse cosh() with cos().

Example 2: A Different Input

<?php

echo round(cosh(1), 3);

Output:

1.543

Input values are in the real-number domain; large values may overflow to INF. Do not confuse cosh() with cos().

Practical Example: Applying It in a Program

<?php

$inputs = [-1, 0, 1]; foreach ($inputs as $input) { echo round(cosh($input), 4) . PHP_EOL; }

Output:

1.5431
1
1.5431

Input values are in the real-number domain; large values may overflow to INF. Do not confuse cosh() with cos().

Important Behavior and Edge Cases

  • Key behavior: Input values are in the real-number domain; large values may overflow to INF. Do not confuse cosh() with cos().
  • Environment: Core PHP.

Comparison With Related Functions

FunctionPurpose
cosh()Calculates the hyperbolic cosine of a number.
cos()cos() computes ordinary cosine of radians; cosh() computes hyperbolic cosine.

Common Beginner Mistakes

MistakeCorrect Approach
Ignoring this behavior: Input values are in the real-number domain; large values may overflow to INFInput values are in the real-number domain; large values may overflow to INF. Do not confuse cosh() with cos().

Key Takeaways

  • Calculates the hyperbolic cosine of a number.
  • Input values are in the real-number domain; large values may overflow to INF. Do not confuse cosh() with cos().
  • Core PHP.

Summary: Input values are in the real-number domain; large values may overflow to INF. Do not confuse cosh() with cos().

Share this resourceSend this page to someone who may find it useful.