Source Code:
(back to article)
<?php $colors = array("red", "green", "blue", "yellow"); $indicesToMove = array(2, 0, 3, 1); // Move elements to new indices $reorderedElements = array_map(function($i) use ($colors) { return $colors[$i]; }, $indicesToMove); $newArray = array_merge($reorderedElements); // Output: Array ( [0] => blue [1] => red [2] => yellow [3] => green ) ?>
Result:
Report an issue