Finds the position of $item in $array
@param $item
@param $array
@return int
321621
private function binarySearch($item, $array)
    {
        $low = 0;
        $high = count($array);
        while ($high - $low > 1) {
            $center = ($high + $low) / 2;
//            print("high=$high, low=$low, center=$center -- val=".(int)explode(';', $array[$center])[1]."<br>");
            if ((int)explode(';', $array[$center])[1] < (int)$item) {
                $low = $center;
            } else
                $high = $center;
        }
        if ($high == count($array))
            throw new ParseError(self::class . " - Error while searching for position of item=" . $item . "high=" . $high . "; val=" . $array[$high]);
        else
            return $high + 1;
    }
501728
private function isAssocArray($item): bool
    {
        if (!is_array($item)) {
            // Is not an array at all
            return false;
        }

        if ($item === []) {
            // Treat empty array as Sequential
            return false;
        }

        // Check if keys are equal to sequence of 0 .. n-1
        return array_keys($item) !== range(0, count($item) - 1);
    }
1081047
public function findParent(&$items, $item)
    {
        return $items->filter(function ($element) use ($item) {
            return $item->parent_id == $element->id;
        })->first();
    }
530302
public function offsetSet($offset, $item)
	{
		if ($offset === null)
		{
			$this->_data[] = $item;
			$this->_total = count($this->_data);
		}
		else
		{
			$this->_data[$offset] = $item;
		}
	}
631957
protected function getItemTotal($item)
    {
        return $item->getRowTotal() - $item->getDiscountAmount() + $item->getTaxAmount() + $item->getWeeeTaxAppliedRowAmount();
    }
1143659
public function process(array $items)
    {
        $total = count($items);
        for ($i = 1; $i < $total; $i++) {
            for ($j = 0; $j < $total - $i; $j++) {
                if (!$items[$j]->getDate() || !$items[$j + 1]->getDate()) {
                    continue;
                }
                if ($items[$j]->getDate()->getTimestamp() > $items[$j + 1]->getDate()->getTimestamp()) {
                    continue;
                }
                $aux = $items[$j + 1];
                $items[$j + 1] = $items[$j];
                $items[$j] = $aux;
            }
        }

        return $items;
    }
563744
private function findItemIn($item, $key)
	{
		$array = $this->find($key);
		if($array) return $this->array_get($array, $item);
		return false;
	}
609220
public static function GetMaxDepth( array $array ) : int
   {

      if ( \count( $array ) < 1 )
      {
         return 0;
      }

      $c = 1;
      foreach ( $array as $v )
      {

         if ( \is_array( $v ) )
         {
            $x = 1 + static::GetMaxDepth( $v );
            if ( $x > $c )
            {
               $c = $x;
            }
         }

      }

      return $c;

   }
860340
protected function _isItemActive(array $item): bool
    {
        if (empty($item['url'])) {
            return false;
        }
        $current = $this->_currentUrl;
        if (!empty($item['url']['plugin']) && $item['url']['plugin'] != $current['plugin']) {
            return false;
        }
        if ($item['url']['controller'] == $current['controller'] && $item['url']['action'] == $current['action']) {
            $this->_controllerActive = $current['controller'];
            $this->_actionActive = $item['url']['action'];

            return true;
        }
        if (!empty($this->_actionActive) && $item['url']['controller'] == $current['controller']) {
            $this->_controllerActive = $current['controller'];

            return true;
        }

        return false;
    }
871246
public static function getPrevKey($key, array $array) {
		$keys = array_keys($array);
		$found_index = array_search($key, $keys);
		if($found_index === false || $found_index === 0)
			return false;
		return $keys[$found_index - 1];
	}
1324341
public function lastIndexOf($collection=null, $item=null) {
    list($collection, $item) = self::_wrapArgs(func_get_args(), 2);
    
    $collection = self::_collection($collection);
    
    krsort($collection);
    $__ = new self;
    return self::_wrap($__->indexOf($collection, $item));
  }
948297
protected static function sortItems(array &$items)
    {
        usort($items, function ($a, $b)
        {
            if ($a['order'] === $b['order']) {
                return 0;
            }

            return ($a['order'] < $b['order']) ? -1 : 1;
        });
    }
426368
private function getNextItem(Tag $item, $items)
    {
        $currentItem = $items[0];

        while ($currentItem !== null and $currentItem !== $item) {
            $currentItem = next($items);
        }

        $next = next($items);

        return $next !== false ? $next : null;
    }
576710
public function indexOf( $item ) {

			for ( $i=0; $i < $this->len; $i++ ) {

				if ( $this->compare( $item, $this->items[$i] ) === 0 ) {
					return $i;
				}

			}

			return -1;

		}
317802
private function _arrayShiftAssoc(array &$array)
    {
        if (empty($array)) {
            return null;
        }
        
        // Make sure that the array variable is pointing to the beginning of the array
        reset($array);
        
        // Now, get the first key and first value
        $firstKey   = key($array);
        $firstValue = current($array); // equivalent to $array[$firstKey]
        
        unset($array[$firstKey]);
        
        return [$firstKey, $firstValue];
    }
1006725
public static function getNextKey($key, array $array) {
		$keys = array_keys($array);
		$found_index = array_search($key, $keys);
		if($found_index === false || $found_index + 1 === count($keys))
			return false;
		return $keys[$found_index + 1];
	}
988088
public function add_item( $item ) {
		if ( is_array( $item ) ) {
			foreach ( $item as $single_item ) {
				$this->add_item( $single_item );
			}
		} else {
			$priority                   = $item->get_priority();
			$this->items[ $priority ][] = $item;
		}
	}