• PHP Video Tutorials

PHP - Stats Skew() Function



Definition and Usage

The stats_skew() function can compute the skewness of the data in an array. Skewness refers to distortion or asymmetry in a symmetrical bell curve, or normal distribution.

Syntax

  float stats_skew( array $a )

Parameters

Sr.No Parameter Description
1

a

The input array

Return Values

The stats_skew() function can return the skewness of values in "a" or false if "a" is empty or is not an array.

Dependencies

This function was first introduced in statistics extension (PHP 4.0.0 and PEAR 1.4.0). We have used latest release of stats-2.0.3 (PHP 7.0.0 or newer and PEAR 1.4.0 or newer) for this tutorial

Example

In the following example returns the skewness of values in an array.

<?php
   var_dump(sprintf("%2.9f", stats_skew(array(99,333,5, 7, 2, 4))));
?>

Output

This will produce following result −

string(11) "1.505674536"

Example

Following is an error case. In the following example, we pass empty array. A warning is displayed in logs.

<?php
   // error cases
   var_dump(stats_skew(array())); // empty array
?>

Output

This will produce following result and a warning in logs PHP Warning: stats_skew(): The array has zero elements

bool(false)
Advertisements