• PHP Video Tutorials

PHP - Stats Absolute Deviation() Function



Definition and Usage

The stats_absolute_deviation() function can return absolute deviation of an array of values.

Syntax

float stats_absolute_deviation( array $a )

Parameters

Sr.No Parameter Description
1

a

The array of data to find the standard deviation for. Note that all values of the array will be cast to float.

Return Values

This function returns the absolute deviation 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

Following example creates a standard absolute deviation of an array:

<?php
   $arr = array(1,37,4,5,47,87);
   var_dump(stats_absolute_deviation($arr));
?>

Output

This will produce following result −

float(26.833333333333)

Example

Following example returns false when array is empty:

<?php
   $arr = array();
   var_dump(stats_absolute_deviation($arr));
?>

Output

This will produce following result −

bool(false)

Example

Following example raises a warning as we pass a tsring value instead of an array:

<?php
   $arr = 'this is a string';
   var_dump(stats_absolute_deviation($arr));
?>

Output

This will produce following result −

NULL

This will produce following result and a warning in logs PPHP Warning: stats_absolute_deviation() expects parameter 1 to be array, string given in <file_path>/stats-absolute-deviation.php on line 3

Advertisements