in_array的实现,大概用脚想一下,就能明白是foreach一遍数组,进行一一比对,查看了源码,果不其然,下面列出关键源码:
......
if (Z_TYPE_P(value) == IS_LONG) {
//下面是foreach了
ZEND_HASH_FOREACH_KEY_VAL(Z_ARRVAL_P(array), num_idx, str_idx, entry) {
//判断两个zval的value值相等
if (fast_equal_check_long(value, entry)) {
if (behavior == 0) {
RETURN_TRUE;
}
......
}
} ZEND_HASH_FOREACH_END();
}
......
if (Z_TYPE_P(value) == IS_LONG) {
//下面是foreach了
ZEND_HASH_FOREACH_KEY_VAL(Z_ARRVAL_P(array), num_idx, str_idx, entry) {
//判断两个zval的value值相等
if (fast_equal_check_long(value, entry)) {
if (behavior == 0) {
RETURN_TRUE;
}
......
}
} ZEND_HASH_FOREACH_END();
}
......
转载请注明:小Y » php源码学习-in_array实现