Skip to content

Instantly share code, notes, and snippets.

@schnipseljagd
Last active December 28, 2015 00:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save schnipseljagd/7410956 to your computer and use it in GitHub Desktop.
Save schnipseljagd/7410956 to your computer and use it in GitHub Desktop.
<?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