1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77
|
<?php
// File array_functions.inc.php / ibWebAdmin
// Purpose functions for juggling with arrays
// Author Lutz Brueckner <irie@gmx.de>
// Copyright (c) 2000, 2001, 2002, 2003 by Lutz Brueckner,
// published under the terms of the GNU General Public Licence v.2,
// see file LICENCE for details
// Created <00/10/23 12:10:07 lb>
//
// $Id: array_functions.inc.php,v 1.4 2003/08/11 20:09:03 lbrueckner Exp $
//
// swap the elements $from and $to in $arr, return the array
//
function array_swap_elements($arr, $from, $to) {
for ($i=0; $i<count($arr); $i++) {
if ($i == $from) {
$newarr[] = $arr[$to];
}
elseif ($i == $to) {
$newarr[] = $arr[$from];
}
else {
$newarr[] = $arr[$i];
}
}
return $newarr;
}
//
// move the element from $pos to the top of the array, return the array
//
function array_moveto_top($arr, $pos) {
$newarr[] = $arr[$pos];
for ($i=0; $i<count($arr); $i++) {
if ( $i != $pos) {
$newarr[] = $arr[$i];
}
}
return $newarr;
}
//
// move the element from $pos to the end of the array, return the array
//
function array_moveto_end($arr, $pos) {
for ($i=0; $i<count($arr); $i++) {
if ( $i != $pos) {
$newarr[] = $arr[$i];
}
}
$newarr[] = $arr[$pos];
return $newarr;
}
//
// determine the maximum index from an numeric indexed array
//
function get_max_key($arr) {
end($arr);
list($key, $val) = each($arr);
return $key;
}
?>
|