Related Articles

# PHP | pow( ) Function

• Last Updated : 08 Mar, 2018

Many a times it happens that while solving mathematical expressions we require a number to be raised by a specific value. We also call this power of a number. Example of such cases is Exponential expression, cube root, square root etc. Thus in such cases, PHP’s inbuilt function pow() comes to an aid.
The pow() function in PHP is used to calculate a base raised to the power of exponent. It is a generic function which can be used with number raised to any value.It takes two parameters which are the base and exponent and returns the desired answer.
If both the arguments passed are non-negative integers and the result can be represented as an integer, the result is returned with integer type, otherwise, it is returned as a float. We already have discussed about pow() function in brief in the article PHP | Math functions. In this article we will learn about the pow() function in details.

Syntax:

`number pow(\$base, \$exp)`

Parameters : The pow() function accepts two parameters as shown in the above syntax:

1. \$base : It is used to specify the base.
2. \$exponent : It is used to specify the exponent.

Return Value: It returns a number (integer or floating-point) which is equal to \$base raised to the power of \$exponent.

Examples:

```Input : pow(3, 2)
Output : 9

Input : pow(-3, 2)
Output : 9

Input : pow(-3, -3)
Output : 0.037037037037037

Input : pow(-3, -3.2)
Output : NaN
```

Below programs illustrate the working of pow() in PHP:

1. When both the parameters passed are positive:
 ``

Output:

`9`
2. When the \$base is negative and \$exponent is a positive even number:
 ``

Output:

`9`
3. When \$base is negative and \$exponent is a negative odd number:
 ``

Output:

`0.037037037037037`
4. When \$base is negative and \$exponent is a negative number with decimal places:
 ``

Output:

`NaN`

Important Points To Note:

• pow() function is used to solve exponential expressions.
• It is a generic function that can be used for any exponent value.
• Avoid using pow() function if you want to calculate square root of a function since PHP already has an inbuilt function for calculating square roots and it is much more efficient than pow().

My Personal Notes arrow_drop_up
{"ft_lang_label":"__label__en","ft_lang_prob":0.7253842,"math_prob":0.97739977,"size":2284,"snap":"2021-31-2021-39","text_gpt3_token_len":552,"char_repetition_ratio":0.14298245,"word_repetition_ratio":0.08997429,"special_character_ratio":0.2714536,"punctuation_ratio":0.16348195,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.9977606,"pos_list":[0],"im_url_duplicate_count":[null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2021-07-27T06:46:33Z\",\"WARC-Record-ID\":\"<urn:uuid:c20faad9-44a4-431a-9113-98751b57371c>\",\"Content-Length\":\"107657\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:1b383c05-3308-4825-8cd7-6a48c71e1d36>\",\"WARC-Concurrent-To\":\"<urn:uuid:e5225045-cda0-41e2-9234-9c1da4b4e90c>\",\"WARC-IP-Address\":\"23.218.216.148\",\"WARC-Target-URI\":\"https://www.geeksforgeeks.org/php-pow-function/?ref=rp\",\"WARC-Payload-Digest\":\"sha1:2L5GTEXV2PNQVYYBCYFHWEUAZXZG7A3M\",\"WARC-Block-Digest\":\"sha1:7DUMXDRR2VHPL6CTIIHWWBMMMT62NYQN\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2021/CC-MAIN-2021-31/CC-MAIN-2021-31_segments_1627046152236.64_warc_CC-MAIN-20210727041254-20210727071254-00533.warc.gz\"}"}