Last active
December 28, 2015 00:09
-
-
Save schnipseljagd/7410956 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function isAssoc($arr) | |
{ | |
return array_keys($arr) !== range(0, count($arr) - 1); | |
} | |
function is_assoc($array) { | |
return (bool)count(array_filter(array_keys($array), 'is_string')); | |
} | |
function isSequential($arr) | |
{ | |
return array_values($arr) === $arr; | |
} | |
function is_indexed_array($arr) { | |
for (reset($arr); is_int(key($arr)); next($arr)); | |
return is_null(key($arr)); | |
} | |
function is_sequential_array($arr, $base = 0) { | |
for (reset($arr), $base = (int) $base; key($arr) === $base++; next($arr)); | |
return is_null(key($arr)); | |
} | |
$fatArray = array(); | |
for ($i = 0; $i < 999999; $i++) { | |
$fatArray[$i] = rand(); | |
} | |
#$fatArray['test'] = 1; | |
echo $before = memory_get_peak_usage() . "\n"; | |
echo $timeBefore = microtime(true); | |
var_dump(isSequential($fatArray)); | |
echo $timeAfter = microtime(true); | |
echo $after = memory_get_peak_usage() . "\n"; | |
echo ($timeAfter-$timeBefore) . " s\n"; | |
echo ($after-$before)/1024/1024 . " MB\n"; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment