Search code examples
phpsumintegeroutput

Print sum of a calculation without metadata prefix provided by var_dump()


I have this code which calculates the sum of "letter numbers" in a string, but its output is: int(64). 64 is the total of T(20), E(2), S(19), T(20) --> 20+5+19+20=64.

I want only number as output 64 instead of int(64).

Here is the code:

$data = "test";
$testResult = array_values(
    array_merge(
        array_fill_keys(
            range('A','Z'),
            0
        ),
        array_count_values(
            str_split(
                strtoupper($data)
            )
        )
    )
);
$wordCount = 0;
foreach ($testResult as $letterValue => $letterCount) {
    $wordCount += ++$letterValue * $letterCount;
}
var_dump($wordCount);

Solution

  • int(64) is a feature of var_dump() DOCs. Just echo the variable and you should get normal numerical output.