Clean a stack (an array) leaving just one set of an entry for the $clean_by variable

@param array $stack The stack to clean
@param string $clean_by The variable name to check
@return array Return the stack cleaned with only one instance of $clean_by
184391
protected function cleanStack(array $stack, $clean_by = null)
    {
        $new_stack = array();
        foreach ($stack as $_entry) {
            if (is_array($_entry) && !empty($clean_by)) {
                if (isset($_entry[$clean_by]) && !array_key_exists($_entry[$clean_by], $new_stack)) {
                    $new_stack[ $_entry[$clean_by] ] = $_entry;
                }
            } elseif (is_string($_entry)) {
                $ok = array_search($_entry, $new_stack);
                if (false===$ok) {
                    $new_stack[] = $_entry;
                }
            }
        }
        return array_values($new_stack);
    }
879211
public static function clean(array $objects) {
			foreach ($objects as $k => $obj) {
				$fields = self::getSObjectFields($obj);

				if ($fields === null) {
					unset($objects[$k]);

					continue;
				}

				foreach ($fields as $k => $v) {
					if ($v === null || is_string($v) && strlen($v) === 0) {
						if (!isset($obj->fieldsToNull))
							$obj->fieldsToNull = [];

						$obj->fieldsToNull[] = $k;

						unset($fields[$k]);

						continue;
					}

					$fields[$k] = $this->converter->convertForUpdateOrCreate($v);
				}

				$obj = self::updateSObjectFields($obj, $fields);
			}

			return $objects;
		}
996946
public static function filtered($classes = array(), $files = array(), &$stack = null)
    {
        $skip_self_trace = 0;
        if ($stack === null) {
            $stack = debug_backtrace();
        }

        $classes = array_merge((array) $classes, array(__CLASS__));
        // Note: in a php backtrace, the class refers to the target of
        // invocation, whereas the file and line indicate where the invocation
        // happened.
        // E.g.
        //     [file] => /mover/backend/test/Belt/Support/TracePrinter.php
        //     [line] => 18
        //     [function] => debug
        //     [class] => Belt\Trace
        // Here, one might expect class to be 'Belt\Trace'
        $files = array_merge((array) $files, array(__FILE__));

        $filtered_stack = array();
        foreach ($stack as $index => $item) {
            $file = Arrays::get($item, 'file', null);
            // So given the long comment above, we cheat by looking
            // at our caller's class.
            $class = Arrays::get($stack, ($index).'.class', null);
            if (
                (in_array($file, $files))
                // ||
                // ($index != 0 && in_array($class, $classes))
            ) {
                $skip_self_trace++;
                continue;
            } else {
                $filtered_stack[] = $item;
            }
        }
        return $filtered_stack;
    }
853437
private function countStackMessages(Stack $stack)
    {
        return 1 + array_sum(array_map(function (Stack $child) {
            return $this->countStackMessages($child);
        }, $this->getChildrenStacks($stack)));
    }
5272
public function clean()
    {
        $cleanCallback = function ($allCleaned, $cache) {
            return $allCleaned && $cache->clean();
        };
        return array_reduce($this->caches, $cleanCallback, true);
    }
714025
protected function _cleanFilesStack()
    {
        if (true===$this->isCleaned_files_stack) {
            return;
        }

        $new_stack = array();
        foreach ($this->files_stack as $_file) {
            if (is_object($_file) && ($_file instanceof \SplFileInfo)) {
                $new_stack[] = $_file;
            } elseif (is_string($_file) && @file_exists($_file)) {
                $new_stack[] = new \SplFileInfo($_file);
            } elseif (false===$this->silent) {
                throw new \RuntimeException(
                    sprintf('[Compressor] Source to process "%s" not found!', $_file)
                );
            }
        }
        $this->files_stack = $new_stack;
        $this->isCleaned_files_stack = true;
    }
960246
def fetch_stacks(stack_id = nil)
      cache.locked_action(:stacks_lock) do
        logger.info "Lock aquired for stack update. Requesting stacks from upstream. (#{Thread.current})"
        if stack_id
          single_stack = connection.stacks.get(stack_id)
          stacks = single_stack ? {single_stack.id => single_stack} : {}
        else
          stacks = Hash[
            connection.stacks.reload.all.map do |stack|
              [stack.id, stack.attributes]
            end
          ]
        end
        if cache[:stacks].value
          existing_stacks = MultiJson.load(cache[:stacks].value)
          # Force common types
          stacks = MultiJson.load(MultiJson.dump(stacks))
          if stack_id
            stacks = existing_stacks.to_smash.deep_merge(stacks)
          else
            # Remove stacks that have been deleted
            stale_ids = existing_stacks.keys - stacks.keys
            stacks = existing_stacks.to_smash.deep_merge(stacks)
            stale_ids.each do |stale_id|
              stacks.delete(stale_id)
            end
          end
        end
        cache[:stacks].value = stacks.to_json
        logger.info "Stack list has been updated from upstream and cached locally"
      end
      @initial_fetch_complete = true
    end
106209
public static function trace(array $stack) {
		$result = [];

		foreach ($stack as $frame) {
			if (isset($frame['function'])) {
				if (isset($frame['class'])) {
					$result[] = trim($frame['class'], '\\') . '::' . $frame['function'];
				} else {
					$result[] = $frame['function'];
				}
			}
		}
		return $result;
	}
1264473
private function cleanOut()
    {
        //====================================================================//
        //  Free current tasks list
        $this->tasks = null;
        //====================================================================//
        //  Initiate a new tasks list
        $this->tasks = new ArrayObject(array(), ArrayObject::ARRAY_AS_PROPS);
        //====================================================================//
        //  Free current output buffer
        $this->outputs = null;
        //====================================================================//
        //  Initiate a new output buffer
        $this->outputs = new ArrayObject(array(), ArrayObject::ARRAY_AS_PROPS);

        return true;
    }
363295
protected function resolve(string $abstract, array &$stack = []): Dependency
    {
        if (isset($this->aliases[$abstract])) {
            $alias = $this->aliases[$abstract];

            if (in_array($alias, $stack)) {
                $stack[] = $alias;
                $error = implode(' => ', $stack);
                throw new BindingException("Circular reference detected: $error");
            } else {
                $stack[] = $alias;
                return $this->resolve($alias, $stack);
            }
        }

        if (!isset($this->bindings[$abstract])) {
            $this->bind($abstract, null);
        }

        return $this->bindings[$abstract];
    }
63190
public static function stack(string $stack)
    {
        if (! static::hasStack($stack)) {
            static::$stacks[$stack] = new StickyContextStack;
        }

        return static::$stacks[$stack];
    }
191305
public static function cleanArray(array &$arr)
    {
        foreach ($arr as $k => $v) {
            if (is_array($v)) {
                self::cleanArray($arr[$k]);
            } else {
                $arr[$k] = stripslashes($v);
            }
        }
    }
803003
public static List<StackTraceElement> cleanup(StackTraceElement[] stack) {
        List<StackTraceElement> elements = new ArrayList<>();
        if (stack == null) {
            return elements;
        } else {
            for (StackTraceElement element : stack) {
                // Remove all iPOJO calls.
                if (element.getMethodName().startsWith("__M_")) {
                    String newMethodName = element.getMethodName().substring("__M_".length());
                    elements.add(new StackTraceElement(element.getClassName(), newMethodName, element.getFileName(),
                            element.getLineNumber()));
                } else if (element.getLineNumber() >= 0) {
                    elements.add(element);
                }
            }
        }
        return elements;
    }
839948
protected static function formatDumpStack($stack, $var)
    {
        $ret = (count($stack) ? join('', $stack) : '');
        $ret .= '<' . (
            is_array($var)
                ? 'array(' . count($var) . ')'
                : get_class($var)
            ) . '>';

        return $ret;
    }
315314
public function stack($types = [])
    {
        if (is_string($types)) {
            $types = explode(',', $types) ?: [];
            $types = array_filter(array_map('trim', $types));
        }

        $files = $this->stack->getList($types);

        return $files;
    }
1224388
public function getArray(bool $clean_keyboard = true) : array
    {
        if (empty($this->inline_keyboard)) {
            throw new BotException("Inline keyboard is empty");
        }

        // Create a new array to put the buttons
        $reply_markup = ['inline_keyboard' => $this->inline_keyboard];

        if ($clean_keyboard) {
            $this->clearKeyboard();
        }

        return $reply_markup;
    }
921694
public function clean($array)
	{
		//set the $inputElement
		$this->inputElement = $array;

		//loop throught the input array removing empty elements and return resultant array
		$this->outputElement = array_values(array_filter($array, function($item){

				return ! empty($item);

		}));

		//return this self same class
		return $this;

	}