用js实现sleep, 用php实现parseInt

用js实现sleep:

//使用方法:
sleep(3);
//sleep
function sleep(numberMillis) {
    var now = new Date();
    var exitTime = now.getTime() + numberMillis;
    while (true) {
        now = new Date();
        if (now.getTime() > exitTime)
            return;
    }
}

用php实现parseInt

//使用方法:
parseInt('08', 16); //8
parseInt('0F', 16); //15
parseInt('12', 16); //18
parseInt('AB', 16); //171
//parseInt
function parseInt($string, $radix = '0') {
	if(is_array($string)) {
		foreach($string as $key => $val) {
			$res[$key] = parseInt($val, $radix);
		}
	}else{
		$res = intval($string, $radix);
	}
	return (int)($res);
}

Leave a Reply