[Typo3-dev] RFC: t3lib_div suggestion

Kraft Bernhard kraftb at kraftb.at
Tue Mar 29 20:00:55 CEST 2005


Hallo list,

I have a suggestion for t3lib_div. I think it would be correct place.

It could even be a global function as it is another array modification function which
is not available in PHP by default. I call it array_swap.

It's defined like this:
----------snip--------------
  function array_swap($array, $start1, $length1, $start2, $length2) {
       $a0 = array_slice($array, 0, $start1);
       $a1 = array_slice($array, $start1, $length1);
       $a2 = array_slice($array, $start1+$length1, $start2-($start1+$length1));
       $a3 = array_slice($array, $start2, $length2);
       $a4 = array_slice($array, $start2+$length2);
       return array_merge($a0, $a3, $a2, $a1, $a4);
    }
----------snip--------------

what it does is if you give it an array like:
{ 1  2  3  4  5 }
And call it with
$entries = whatever::array_swap($entries, 1, 1, 2, 1);
it will swap the values ranging from offset 1 with a length of 1 ( 2 )
with the values ranging from offset 2 with a length of 1 ( 3 )
so the result will be:
{ 1  3  2  4  5 }
2 and 3 swapped.
I use such a function for swapping rows when a user clicks a move-up or
move-down button.

At the moment the functions makes strange things if called with arguments where
values are negative (which is normally allowed with the php array functions and makes
sensefull things) or when start2 is smaller than start1+length1 ....


Comments ?

greets,
Bernhard






More information about the TYPO3-dev mailing list