for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
namespace Subreality\Dilmun\Anshar\Utils;
class ArrayHelper
{
/** @var array */
protected $array;
/**
* ArrayHelper constructor. Accepts and stores an array.
*
* @throws \InvalidArgumentException if not initialized with an array
* @param mixed[] $array The array needing help
*/
public function __construct($array)
if (!is_array($array)) {
throw new \InvalidArgumentException("Supplied array is not an array");
}
$this->array = $array;
* Returns the value corresponding with a supplied key; returns FALSE if the supplied key does not exist within
* the array.
* **WARNING** This function may return FALSE or a non-Boolean value that evaluates to FALSE even if a supplied
* key exists
* @param int|string $key The key to look up
* @return bool|mixed Returns FALSE if the supplied key does not exist within the array
* Returns the value corresponding with the key otherwise
public function valueLookup($key)
$value = false;
if (array_key_exists($key, $this->array)) {
$value = $this->array[$key];
return $value;
* Returns a copy of the array with numeric key/value pairs stripped.
* Preserves the original array.
* @return mixed[] A copy of the array with numeric key/value pairs stripped
public function removeNumericKeys()
$non_numeric_keys = $this->array;
foreach ($this->array as $key => $value) {
if (is_int($key)) {
unset($non_numeric_keys[$key]);
return $non_numeric_keys;