Last active
December 9, 2016 09:49
-
-
Save airani/c3dc00cb98b4cae698ac877f55e84ae1 to your computer and use it in GitHub Desktop.
Move an array item from an index to another index position
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* ArrayHelper | |
* | |
* @author Ali Irani <[email protected]> | |
*/ | |
class ArrayHelper | |
{ | |
/** | |
* Move an array item from an index to another index position | |
* @param array $array | |
* @param int $from | |
* @param int $to | |
* | |
* @return array | |
*/ | |
public static function moveItem($array, $from, $to) | |
{ | |
$item = array_splice($array, $from, 1); | |
array_splice($array, $to, 0, $item); | |
return $array; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Example: