- microtime: documentation ( source)
- shuffle: documentation ( source)
- array_diff: documentation ( source)
- range: documentation ( source)
- printf: documentation ( source)
<?php
class abc {
function abc() {
$this->abc = 'Hello';
}
function bcd() {
$bcd = ' World';
return $this->abc . $bcd;
}
}
$abc = new abc();
echo $abc->bcd();
$bcd = range( 1, 100 );
foreach( $bcd as $def ) {
$efg = $def;
}
function better_array_diff($a, $b) {
$map = array();
foreach($a as $val) $map[$val] = 1;
foreach($b as $val) if(isset($map[$val])) unset($map[$val]);
return $map;
}
$a = range(1, 10000);
$b = range(5000, 15000);
shuffle($a);
shuffle($b);
$ts = microtime(true);
array_diff($a, $b);
printf("array_diff=%.4f\n", microtime(true) - $ts);
$ts = microtime(true);
better_array_diff($a, $b);
printf("better_array_diff=%.4f\n", microtime(true) - $ts);