mirror of
https://github.com/lubuntu-team/lubuntu.me.git
synced 2025-02-23 08:11:08 +00:00
24 lines
569 B
PHP
24 lines
569 B
PHP
|
<?php
|
||
|
|
||
|
/**
|
||
|
* From this SO answer by Halil Özgür: https://stackoverflow.com/a/18781630/3710600
|
||
|
*
|
||
|
* Works with both integer and string positions.
|
||
|
*
|
||
|
* @param array $array
|
||
|
* @param int|string $position
|
||
|
* @param mixed $insert
|
||
|
*/
|
||
|
function siteorigin_widgets_array_insert( &$array, $position, $insert ) {
|
||
|
if ( is_int( $position ) ) {
|
||
|
array_splice( $array, $position, 0, $insert );
|
||
|
} else {
|
||
|
$pos = array_search( $position, array_keys( $array ) );
|
||
|
$array = array_merge(
|
||
|
array_slice( $array, 0, $pos ),
|
||
|
$insert,
|
||
|
array_slice( $array, $pos )
|
||
|
);
|
||
|
}
|
||
|
}
|