Skip to content

Commit

Permalink
Add ArrayType::unsetColumn
Browse files Browse the repository at this point in the history
  • Loading branch information
Cosmologist committed Nov 8, 2018
1 parent 0144349 commit 4ca5cbe
Showing 1 changed file with 34 additions and 12 deletions.
46 changes: 34 additions & 12 deletions src/Gears/ArrayType.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,18 +89,6 @@ public static function unsetValue($array, $value)
return $array;
}

/**
* Check if array is associative
*
* @param array $array Array
*
* @return bool
*/
public static function checkAssoc($array)
{
return (bool) count(array_filter(array_keys($array), 'is_string'));
}

/**
* Cast value to array
*
Expand All @@ -124,6 +112,18 @@ public static function cast($value)
return [$value];
}

/**
* Check if array is associative
*
* @param array $array Array
*
* @return bool
*/
public static function checkAssoc($array)
{
return (bool) count(array_filter(array_keys($array), 'is_string'));
}

/**
* Merge arrays
*
Expand Down Expand Up @@ -359,4 +359,26 @@ public static function average($array)
{
return array_sum($array) / count($array);
}

/**
* Remove a specified column from in the input array
*
* @param array $array The input array.
* @param mixed $column The column of values to return.
* This value may be the integer key of the column you wish to retrieve,
* or it may be the string key name for an associative array
*
* @return array
*/
public static function unsetColumn($array, $column)
{
foreach ($array as $key => $row) {
if (array_key_exists($column, $row)) {
unset($array[$key][$column]);
}

}

return $array;
}
}

0 comments on commit 4ca5cbe

Please sign in to comment.