Skip to content
This repository was archived by the owner on Jan 31, 2020. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 44 additions & 0 deletions benchmark/ArrayUtilsBench.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/

namespace ZendBench\Stdlib;

use PhpBench\Benchmark\Metadata\Annotations\Iterations;
use PhpBench\Benchmark\Metadata\Annotations\Revs;
use PhpBench\Benchmark\Metadata\Annotations\Warmup;
use Zend\Stdlib\ArrayUtils;

/**
* @Revs(1000)
* @Iterations(10)
* @Warmup(2)
*/
class ArrayUtilsBench
{
public function benchHasStringKeys()
{
ArrayUtils::hasStringKeys([
'key' => 'value',
]);
}

public function benchHasIntegerKeys()
{
ArrayUtils::hasIntegerKeys([
1 => 'value',
]);
}

public function benchHasNumericKeys()
{
ArrayUtils::hasNumericKeys([
'1' => 'value',
]);
}
}
6 changes: 3 additions & 3 deletions src/ArrayUtils.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public static function hasStringKeys($value, $allowEmpty = false)
return $allowEmpty;
}

return count(array_filter(array_keys($value), 'is_string')) > 0;
return [] !== array_filter(array_keys($value), 'is_string');
}

/**
Expand All @@ -67,7 +67,7 @@ public static function hasIntegerKeys($value, $allowEmpty = false)
return $allowEmpty;
}

return count(array_filter(array_keys($value), 'is_int')) > 0;
return [] !== array_filter(array_keys($value), 'is_int');
}

/**
Expand All @@ -94,7 +94,7 @@ public static function hasNumericKeys($value, $allowEmpty = false)
return $allowEmpty;
}

return count(array_filter(array_keys($value), 'is_numeric')) > 0;
return [] !== array_filter(array_keys($value), 'is_numeric');
}

/**
Expand Down