@@ 633-643 (lines=11) @@ | ||
630 | * @throws \InvalidArgumentException |
|
631 | * @since 2.0 |
|
632 | */ |
|
633 | public static function insertBeforeKey(array &$original, $value, $key, $isAssoc = false) |
|
634 | { |
|
635 | $pos = array_search($key, array_keys($original)); |
|
636 | ||
637 | if ($pos === false) |
|
638 | { |
|
639 | throw new \InvalidArgumentException('Unknown key before which to insert the new value into the array.'); |
|
640 | } |
|
641 | ||
642 | return $isAssoc ? static::insertAssoc($original, $value, $pos) : static::insert($original, $value, $pos); |
|
643 | } |
|
644 | ||
645 | /** |
|
646 | * Insert value(s) into an array after a specific key |
|
@@ 659-673 (lines=15) @@ | ||
656 | * @throws \InvalidArgumentException |
|
657 | * @since 2.0 |
|
658 | */ |
|
659 | public static function insertAfterKey(array &$original, $value, $key, $isAssoc = false) |
|
660 | { |
|
661 | $pos = array_search($key, array_keys($original)); |
|
662 | ||
663 | if ($pos === false) |
|
664 | { |
|
665 | throw new \InvalidArgumentException('Unknown key after which to insert the new value into the array.'); |
|
666 | } |
|
667 | ||
668 | return $isAssoc ? static::insertAssoc($original, $value, $pos + 1) : static::insert( |
|
669 | $original, |
|
670 | $value, |
|
671 | $pos + 1 |
|
672 | ); |
|
673 | } |
|
674 | ||
675 | /** |
|
676 | * Insert value(s) into an array after a specific value (first found in array) |