In your code

$arr[$i]=$arr[$i]/1000;
$arr1[$i]=$arr[$i];

Your $arr1 is a collection of floats:

Array
(
    [0] => 1.1
    [1] => 3.15
    [2] => 4.4
    [3] => 4.4
    [4] => 5.17
    [5] => 7.45
    [6] => 7.45
    [7] => 7.45
    [8] => 8.23
)

Hence the Can only count STRING and INTEGER values.

You can round it or do something else like cast it to a string etc...

$arr[$i]=$arr[$i]/1000;
$arr1[$i]=(string)$arr[$i];

Also

function sd_square($x, $total) { return pow($x - $mean,2); }

The var $mean is undefined here.

Making those changes:

<?php

echo "Welcome to my project".'<br>'.'<br>'; 
$arr=array(1100,3150,4400,4400,5170,7450,7450,7450,8230 );
$arr1=[]; //<--- define this if all are < 100 its undefined
for($i=0; $i<=8; $i++){
    if ($arr[$i]<100) {  //<-- clean up formatting.
        $arr[$i]=$arr[$i];
    }else{
        $arr[$i]=$arr[$i]/1000;
        $arr1[$i]=(string)$arr[$i]; //<-- cast to string
    }
}

function calculate($arr, $output){

        switch($output){
            case 'mean':
                $count = count($arr)+1;
                $sum = array_sum($arr);
                $total = $sum / $count;
            break;
            case 'median':
                rsort($arr);
                $middle = (count($arr) / 2)+1;
                $total = $arr[$middle-1];
            break;
            case 'mode':
                $v = array_count_values($arr); 
                arsort($v); 
                foreach($v as $k => $v){$total = $k; break;}

            break;

        }
        return $total;
    }

function sd_square($x, $total) { return pow($x - $total,2); } //<--changed to $total
function sd($arr) {
    return sqrt(array_sum(array_map("sd_square", $arr, array_fill(0,count($arr), (array_sum($arr) / count($arr)) ) ) ) / (count($arr)-1) );
}

   if (isset($_POST['select'])) {
    someFunction();
  }

echo '  '.'<br>';
echo "Values: ";
echo json_encode($arr).'<br>';
echo 'Mean: '.calculate($arr, 'mean').'<br>';
echo 'Median: '.calculate($arr, 'median').'<br>';
echo 'Mode: '.calculate($arr1, 'mode').'<br>';
echo "Standart Derivation: ".sd($arr);

Output

Welcome to my project

Values: [1.1,3.15,4.4,4.4,5.17,7.45,7.45,7.45,8.23]
Mean: 4.88
Median: 5.17
Mode: 7.45
Standart Derivation: 2.4035743059961

Sandbox

Answer from ArtisticPhoenix on Stack Overflow
Top answer
1 of 1
1

In your code

$arr[$i]=$arr[$i]/1000;
$arr1[$i]=$arr[$i];

Your $arr1 is a collection of floats:

Array
(
    [0] => 1.1
    [1] => 3.15
    [2] => 4.4
    [3] => 4.4
    [4] => 5.17
    [5] => 7.45
    [6] => 7.45
    [7] => 7.45
    [8] => 8.23
)

Hence the Can only count STRING and INTEGER values.

You can round it or do something else like cast it to a string etc...

$arr[$i]=$arr[$i]/1000;
$arr1[$i]=(string)$arr[$i];

Also

function sd_square($x, $total) { return pow($x - $mean,2); }

The var $mean is undefined here.

Making those changes:

<?php

echo "Welcome to my project".'<br>'.'<br>'; 
$arr=array(1100,3150,4400,4400,5170,7450,7450,7450,8230 );
$arr1=[]; //<--- define this if all are < 100 its undefined
for($i=0; $i<=8; $i++){
    if ($arr[$i]<100) {  //<-- clean up formatting.
        $arr[$i]=$arr[$i];
    }else{
        $arr[$i]=$arr[$i]/1000;
        $arr1[$i]=(string)$arr[$i]; //<-- cast to string
    }
}

function calculate($arr, $output){

        switch($output){
            case 'mean':
                $count = count($arr)+1;
                $sum = array_sum($arr);
                $total = $sum / $count;
            break;
            case 'median':
                rsort($arr);
                $middle = (count($arr) / 2)+1;
                $total = $arr[$middle-1];
            break;
            case 'mode':
                $v = array_count_values($arr); 
                arsort($v); 
                foreach($v as $k => $v){$total = $k; break;}

            break;

        }
        return $total;
    }

function sd_square($x, $total) { return pow($x - $total,2); } //<--changed to $total
function sd($arr) {
    return sqrt(array_sum(array_map("sd_square", $arr, array_fill(0,count($arr), (array_sum($arr) / count($arr)) ) ) ) / (count($arr)-1) );
}

   if (isset($_POST['select'])) {
    someFunction();
  }

echo '  '.'<br>';
echo "Values: ";
echo json_encode($arr).'<br>';
echo 'Mean: '.calculate($arr, 'mean').'<br>';
echo 'Median: '.calculate($arr, 'median').'<br>';
echo 'Mode: '.calculate($arr1, 'mode').'<br>';
echo "Standart Derivation: ".sd($arr);

Output

Welcome to my project

Values: [1.1,3.15,4.4,4.4,5.17,7.45,7.45,7.45,8.23]
Mean: 4.88
Median: 5.17
Mode: 7.45
Standart Derivation: 2.4035743059961

Sandbox

🌐
PHP
php.net › manual › en › function.array-count-values.php
PHP: array_count_values - Manual
array_count_values() returns an array using the values of array (which must be ints or strings) as keys and their frequency in array as values.
🌐
Reintech
reintech.io › blog › phps-array-count-values-function-complete-guide
PHP's `array_count_values()` Function: A Complete Guide
April 14, 2023 - The function only accepts arrays containing strings and integers. When you pass arrays with other types, PHP generates a warning and returns incomplete results: $mixedArray = [1, "one", 2, "two", 3.14, true]; $counts = array_count_values($mixedArray); // Warning: array_count_values(): Can only ...
🌐
GitHub
github.com › wp-seopress › wp-seopress-public › issues › 14
Warning: array_count_values(): Can only count STRING and INTEGER values! · Issue #14 · wp-seopress/wp-seopress-public
February 19, 2020 - I've just caught this in the error logs. It was for a WooCommerce product. Hope the information below would be of some help. :) -- Warning: array_count_values(): Can only count STRING and INTEGER values! in /home/.../public_html/wp-conte...
Author   wp-seopress
🌐
Blogger
bdtryt.blogspot.com › 2019 › 04 › arraycountvalues-can-only-count-string.html
array_count_values(): Can only count string and integer values Announcing the arrival of...
April 23, 2019 - Array ( [0] => 1.1 [1] => 3.15 [2] => 4.4 [3] => 4.4 [4] => 5.17 [5] => 7.45 [6] => 7.45 [7] => 7.45 [8] => 8.23 ) Hence the Can only count STRING and INTEGER values.
Find elsewhere
🌐
Stack Overflow
stackoverflow.com › questions › 50908657 › laravel-how-to-count-specific-array-values › 50908922
php - Laravel : How to count specific array values - Stack Overflow
How can i show my array in blade ... - 2 · – prasoon mudgal Commented Jun 18, 2018 at 18:52 ... It's may be because you may have null values in your array....
🌐
ZetCode
zetcode.com › php-array › array-count-values
PHP array_count_values - Counting Array Values in PHP
... <?php $data = ["a", "b", 3.14, ["array"], null]; $counts = @array_count_values($data); // Suppress warnings print_r($counts); Float, array, and null values trigger warnings and are excluded from the result. Only valid string and integer values are counted in the output.
🌐
Stack Overflow
stackoverflow.com › questions › 48817541 › array-count-values-no-working
php - array_count_values no working - Stack Overflow
February 16, 2018 - but show me error " array_count_values(): Can only count STRING and INTEGER values!" php · multidimensional-array · Share · Improve this question · Follow · asked Feb 15, 2018 at 22:46 · user7474611user7474611 · 1 · Please search StackOverflow for a short while before posting a new question.
🌐
Stack Overflow
stackoverflow.com › questions › 41049302 › count-array-values-php
Count Array values php - Stack Overflow
December 9, 2016 - The built-in function array_count_values() can't calculate the frequency if the elements are not strings or numbers.
🌐
W3Schools
w3schools.com › php › func_array_count_values.asp
PHP array_count_values() Function
boolval() debug_zval_dump() doubleval() is_countable() empty() floatval() get_defined_vars() get_resource_type() gettype() intval() is_array() is_bool() is_callable() is_double() is_float() is_int() is_integer() is_iterable() is_long() is_null() is_numeric() is_object() is_real() is_resource() is_scalar() is_string() isset() print_r() serialize() settype() strval() unserialize() unset() var_dump() var_export() PHP XML Parser
🌐
Tutorial Teacher
tutorialsteacher.com › articles › count-elements-in-array-csharp
Count Elements in Array in C#
This is because an array already has five null elements. For others, it will return the total number of elements. The following example shows how to count the specific elements based on some condition. ... string[] animals = { "Cat", "Alligator", "fox", "donkey", "Cat", "alligator" }; var totalCats = animals.Count(s => s == "Cat"); var animalsStartsWithA = animals1.Count(s => s.StartsWith("a", StringComparison.CurrentCultureIgnoreCase)); int[] nums = { 1, 2, 3, 4, 3, 55, 23, 2, 5, 6, 2, 2 }; var totalEvenNums = nums.Count(n =&gt; n%2==0);
🌐
GeeksforGeeks
geeksforgeeks.org › php › php-array_count_values-function
PHP array_count_values() Function - GeeksforGeeks
June 20, 2023 - This parameter is the array for which we need to calculate the count of values present in it. Return Value: This function returns an associative array with key-value pairs in which keys are the elements of the array passed as parameter and values are the frequency of these elements in an array. Note: If the element is not a string or integer then an E_WARNING is thrown.