* [1] => baz
* [2] => 42
* )
- *
+ *
* [asdf] => Array
* (
* [merp] => bleep
* [1] => 2
* [2] => 3
* )
- *
+ *
* )
- *
+ *
* [quux] => 999
* )
- *
+ *
* Corresponding flattened array:
* Array
* (
* @params int $depth
* (optional) Current recursion depth.
*
+ * @param $array
+ * @param int $maxdepth
+ * @param int $depth
+ *
* @return array
* The new copy of $array.
*
* @param string $field
* Name of the attribute used for sorting.
*
- * @return array
+ * @return array
* Sorted array
*/
static function crmArraySortByField($array, $field) {
* @param array $array
* The input array possibly containing duplicate values.
*
- * @return array
+ * @return array
* The input array with duplicate values removed.
*/
static function crmArrayUnique($array) {
* @param array $array
* (optional) Array to be sorted.
*
- * @return array
+ * @return array
* Sorted array.
*/
static function asort($array = array()) {
*
* @param array $items
* The array from which to remove items.
- * @param string[]|string $key,...
- * When passed a string, unsets $items[$key].
+ *
+ * @internal param string|\string[] $key When passed a string, unsets $items[$key].* When passed a string, unsets $items[$key].
* When passed an array of strings, unsets $items[$k] for each string $k
* in the array.
*/
$node = &$result;
foreach ($keys as $key) {
if (is_array($record)) {
- $keyvalue = $record[$key];
+ $keyvalue = isset($record[$key]) ? $record[$key] : NULL;
} else {
- $keyvalue = $record->{$key};
+ $keyvalue = isset($record->{$key}) ? $record->{$key} : NULL;
}
if (isset($node[$keyvalue]) && !is_array($node[$keyvalue])) {
$node[$keyvalue] = array();
*/
static function collect($prop, $records) {
$result = array();
- foreach ($records as $key => $record) {
- if (is_object($record)) {
- $result[$key] = $record->{$prop};
- } else {
- $result[$key] = $record[$prop];
+ if (is_array($records)) {
+ foreach ($records as $key => $record) {
+ if (is_object($record)) {
+ $result[$key] = $record->{$prop};
+ } else {
+ $result[$key] = $record[$prop];
+ }
}
}
return $result;
* @return mixed
* The value found.
*/
+ /**
+ * @param $regexKey
+ * @param $list
+ * @param null $default
+ *
+ * @return null
+ */
static function valueByRegexKey($regexKey, $list, $default = NULL) {
if (is_array($list) && $regexKey) {
$matches = preg_grep($regexKey, array_keys($list));
return $results;
}
+
+ /**
+ * Get the first elemnet of an array
+ *
+ * @param array $array
+ * @return mixed|NULL
+ */
+ static function first($array) {
+ foreach ($array as $value) {
+ return $value;
+ }
+ return NULL;
+ }
}