utils.inc.php 851 B

123456789101112131415161718192021222324252627282930313233
  1. <?php defined('BX_DOL') or die('hack attempt');
  2. /**
  3. * Copyright (c) UNA, Inc - https://una.io
  4. * MIT License - https://opensource.org/licenses/MIT
  5. *
  6. * @defgroup UnaStudio UNA Studio
  7. * @{
  8. */
  9. function bx_array_insert_before($aInsert, $aSource, $sKey)
  10. {
  11. return bx_array_insert($aInsert, $aSource, $sKey, 0);
  12. }
  13. function bx_array_insert_after($aInsert, $aSource, $sKey)
  14. {
  15. return bx_array_insert($aInsert, $aSource, $sKey, 1);
  16. }
  17. function bx_array_insert($aInsert, $aSource, $sKey, $iDirection = 1)
  18. {
  19. $iPosition = array_search($sKey, array_keys($aSource)) + $iDirection;
  20. if($iPosition == 0)
  21. return $aInsert + $aSource;
  22. if($iPosition == count($aSource))
  23. return $aSource + $aInsert;
  24. return array_slice($aSource, 0, $iPosition, true) + $aInsert + array_slice($aSource, $iPosition, NULL, true);
  25. }
  26. /** @} */