/** * Recursive search key in associative array (depth does not matter) * @param string $key * @param array $array * @param boolean $return (optional) if true then result will be returned (false default) * @return boolean|mixed */ function array_key_exists_recursive($key, $array, $return = FALSE) { foreach ($array as $key_ => $value_) { if (is_array($value_) && $key_ !== $key) { if (FALSE !== ($value = array_key_exists_recursive($key, $value_, $return))) { return $return === FALSE ? TRUE : $value; } } else { if ($key_ == $key) { return $return === FALSE ? TRUE : $array[$key_]; } } } return FALSE; }
* if this stream date is in the current state, we're adding new samples to an existing event */ } else { /** * get the event_id from the event name ($event_count) */ $this_event_id = $Proj->getEventIdUsingUniqueEventName($event_count); /** * get the next available field group on this event to accept the new samples */ $next_field = (count($state_array[$record][$this_event_id]) - 1) / 3; /** * check for new samples on this stream date to add to state */ foreach ($stream_samples AS $barcode => $type) { if (!array_key_exists_recursive($barcode, $state_array[$record])) { foreach ($base_fields_array AS $field_type => $field_name) { $$field_type = str_replace('%', $next_field, $field_name); } update_field_compare($record, $project_id, $this_event_id, $barcode, $data[$record][$this_event_id][$sample_code], $sample_code, $debug); update_field_compare($record, $project_id, $this_event_id, $enum[strtolower($type)], $data[$record][$this_event_id][$sample_type], $sample_type, $debug); update_field_compare($record, $project_id, $this_event_id, 'Y', array_search('1', $data[$record][$this_event_id][$sample_onhand]), $sample_onhand, $debug); $next_field++; } } $event_count++; } } } } } else {
/** * @param $needle * @param $haystack * @return bool */ function array_key_exists_recursive($needle, $haystack) { $result = array_key_exists($needle, $haystack); if ($result) return $result; foreach ($haystack as $v) { if (is_array($v) || is_object($v)) $result = array_key_exists_recursive($needle, $v); if ($result) return $result; } return $result; }