Write a php Program to calculate frequency of each character of string without using HashMap.

Here’s a simple PHP program to calculate the frequency of each character in a string without using a hashmap or associative array — just plain arrays and loops.

Find the frequency of each character in the string:

“Hello, world!”

$count) {
if ($count > 0) {
$result[chr($char)] = $count; // Convert ASCII code back to character
}
}

return $result;
}

// Example usage
$text = “Hello, world!”;
$charFreq = characterFrequency($text);

echo “Character Frequencies:\n”;
foreach ($charFreq as $char => $count) {
echo “$char: $count\n”;
}

Enjoy!