<?php
function foo1($string, $with)
{
if (!$bytes = strlen($with)) {
return true;
}
// Warning check, see http://php.net/manual/en/function.substr-compare.php#refsect1-function.substr-compare-returnvalues
if (strlen($string) < $bytes) {
return false;
}
return substr_compare($string, $with, -$bytes);
}
function foo2($string, $with)
{
if (!$bytes = strlen($with)) {
return true;
}
// Warning check, see http://php.net/manual/en/function.substr-compare.php#refsect1-function.substr-compare-returnvalues
if (strlen($string) < $bytes) {
return false;
}
return substr_compare($string, $with, -$bytes, $bytes);
}
var_dump(foo1('a', 'a'));
var_dump(foo2('a', 'a'));
var_dump(foo1('', ''));
var_dump(foo2('', ''));
var_dump(foo1('a', ''));
var_dump(foo2('a', ''));
var_dump(foo1('', 'a'));
var_dump(foo2('', 'a'));
preferences:
38.52 ms | 402 KiB | 5 Q