Reputation: 47
I came across this line of code while examining the convertFromJSCharcode
function in PHPIDS/Monitor.
foreach ($charcode as $char) {
$char = preg_replace('/\W0/s', '', $char);
if (preg_match_all('/\d*[+-\/\* ]\d+/', $char, $matches)) {
$match = preg_split('/(\W?\d+)/', implode('', $matches[0]), null, PREG_SPLIT_DELIM_CAPTURE);
if (array_sum($match) >= 20 && array_sum($match) <= 127) {
$converted .= chr(array_sum($match));
}
} elseif (!empty($char) && $char >= 20 && $char <= 127) {
$converted .= chr($char);
}
}
How can I compare array_sum($match)
to an integer? My understanding is that array_sum($match)
is a string. The same goes for $cha
r.
Upvotes: 1
Views: 472
Reputation: 2167
As per my understanding array_sum
returns value in
integer or float
if you have an string you may cast it and convert into integer something like (int)$match
& then compare.
Upvotes: 1
Reputation: 80649
Check the array_sum
documentation:
array_sum()
returns the sum of values in an array.[...]
Return Values
Returns the sum of values as an integer or float.
Upvotes: 1
Reputation: 515
From this document, array_sum will return a number (that is integer or float).
Upvotes: 1