PHP 你一不小心就完蛋了

title: PHP 一不小心你就完蛋了
notebook: 资料

tags:PHP

PHP 你一不小心就完蛋了

define("EOLine", "<br/>");

if (strpos('testing', 'test')) {   
    echo "Not".EOLine;
}

'test' is found at position 0, which is interpreted as the boolean 'false'

switch ("a") {
    case 0:
    echo "0".EOLine;
    break;
    case "a":
    echo "a".EOLine;
    break;
}

case “a"并不会被匹配

if (NULL<-1) {
    echo("NULL<-1");
}

NULL<-1 //2233333333333

the standard array comparison is:

function standard_array_compare($op1, $op2)
{
    if (count($op1) < count($op2)) {
        return -1;
    } elseif (count($op1) > count($op2)) {
        return 1;
    }
    foreach ($op1 as $key => $val) {
        if (!array_key_exists($key, $op2)) {
            return null;
        } elseif ($val < $op2[$key]) {
            return -1;
        } elseif ($val > $op2[$key]) {
            return 1;
        }
    }
    return 0;
}

字符串比较还是用函数吧

如果你用“<"活着”>“的话
[1234] vs [1234]
string(4) “1234”
string(4) “1234”
EQUAL !

[1234] vs [ 1234]
string(4) “1234”
string(5) " 1234”
EQUAL !

[1234] vs [\n1234]
string(4) “1234”
string(5) “\n1234”
EQUAL !

[1234] vs [1234 ]
string(4) “1234”
string(5) “1234 "
DIFFERENT !

[1234] vs [1234\n]
string(4) “1234”
string(5) “1234\n”
DIFFERENT !

[1234 ] vs [1234 ]
string(5) “1234 "
string(5) “1234 "
EQUAL !

[12340] vs [1234\n]
string(5) “12340”
string(5) “1234\n”
DIFFERENT !

你可能感兴趣的:(PHP 你一不小心就完蛋了)