<?php
$array=array(0=>'a', 1=>'b', 2=>'c', 3=>'d');
function move($array, $movingkey, $direction) {
//Abbrechen, wenn der Key nicht exisiteiert
$keys = array_keys($array); //Schlüsel extrahieren $pos = array_search($movingkey, $keys); //Position ermitteln unset($keys[$pos]); //Schlüssel aus Array entfernen $offset = $direction=='up' ? $pos+1 : $pos-1; //Offset berechnen
if($offset > count($keys)) $offset=0; //EndOf Korrektur if($offset < 0) $offset=count($keys); //BeginOf Korrektur array_splice($keys, $offset, 0, $movingkey); //Key an neuer Position einfügen foreach($keys as $key){ //Werte auf neue Positionen setzen
$retArr[$key] = $array[$key];
}
return $retArr;
}
?>
PD9waHAKJGFycmF5PWFycmF5KDA9PidhJywgMT0+J2InLCAyPT4nYycsIDM9PidkJyk7CgpwcmludF9yKG1vdmUoJGFycmF5LCAyLCAndXAnKSk7CnByaW50X3IobW92ZSgkYXJyYXksIDMsICd1cCcpKTsKcHJpbnRfcihtb3ZlKCRhcnJheSwgMCwgJ2Rvd24nKSk7CgpmdW5jdGlvbiBtb3ZlKCRhcnJheSwgJG1vdmluZ2tleSwgJGRpcmVjdGlvbikgewoJLy9BYmJyZWNoZW4sIHdlbm4gZGVyIEtleSBuaWNodCBleGlzaXRlaWVydAoJaWYoIWFycmF5X2tleV9leGlzdHMoJG1vdmluZ2tleSwgJGFycmF5KSkgcmV0dXJuICRhcnJheTsKCQoJJGtleXMgPSBhcnJheV9rZXlzKCRhcnJheSk7CQkJCQkJLy9TY2hsw7xzZWwgZXh0cmFoaWVyZW4KIAkkcG9zID0gYXJyYXlfc2VhcmNoKCRtb3ZpbmdrZXksICRrZXlzKTsJCQkvL1Bvc2l0aW9uIGVybWl0dGVsbgogCXVuc2V0KCRrZXlzWyRwb3NdKTsJCQkJCQkJCS8vU2NobMO8c3NlbCBhdXMgQXJyYXkgZW50ZmVybmVuCiAJJG9mZnNldCA9ICRkaXJlY3Rpb249PSd1cCcgPyAkcG9zKzEgOiAkcG9zLTE7CS8vT2Zmc2V0IGJ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