A Utility Class for Simple and Advanced Arrays Operations.
General argument order for all methods: The array to operate on is allways the first argument.
Located in /code/framework/RSArrayUtil/RSArrayUtil.php (line 64)
Returns the array passed as first argument with the element passed as second argument added.
This method can be used in two ways. The first one is to pass the array by value and save the return type of addElement:
1 $array = RSArrayUtil::addElement($array,$element);
The second way is to pass the array by reference (an not care about the return value):
1 RSArrayUtil::addElement($array, $element);
Both ways have the same result!
Returns the array passed as first argument with the elements contained in the array passed as second argument added.
This method can be used in two ways. The first one is to pass the first array by value and save the return type of addElements:
1 $array = RSArrayUtil::addElements($array,$array2);
The second way is to pass the first array by reference (an not care about the return value):
1 RSArrayUtil::addElements($array, $array2);
Both ways have the same result! Please note that the keys of the added elements are not preserved.
Returns true if all elements of the array passed as argument evaluate true.
Returns the number of occurrences of a value in an array.
The comparison is done by the === operator. An other comparison can be forced by passing an instance of the class RSComparator or a class that extends it.
Returns all possible combinations of the elements of an array.
If the array would contain three elements, holding the integers 1, 2 and 3 the returned array of combinations would have a length of 39 and start off like this (if configured not to ignore the order and to allow duplicates):
Returns an array containing all elements from the multidimensional array that where referenced by a key equal to $key.
Example:
1 $array = array(
2 array(
3 'a' => 'zero',
4 'b' => 'one',
5 'c' => 'two'
6 ),
7 array(
8 'a' => 'one',
9 'b' => 'two',
10 'c' => 'three'
11 ),
12 array(
13 'a' => 'two',
14 'b' => 'three',
15 'c' => 'four'
16 )
17 );
18 $aArray = RSArrayUtil::getElementsFromMultiDimArrayByKey($array, 'a');
19 //will echo '0:zero, 1:one, 2:two'
20 echo RSArrayUtil::toString($aArray, ', ', '%key:%val');
Returns true if the the array passed as first argument contains the element passed as second argument.
The comparison is done by http://www.php.net/in_array without type checking by default. An other comparison can be forced by passing an instance of the class RSComparator or a class that extends it. Simple example:
1 $array = array('a', 'b', 'c');
2 if (RSArrayUtil::hasElement($array, 'b')) {
3 echo 'b is contained in the array';
4 }
Complex example using a comperator:
1 class TestElement {
2 var $hash = null;
3 function TestElement($hash)
4 {
5 $this->hash = $hash;
6 }
7 function hashCode()
8 {
9 return $this->hash;
10 }
11 }
12 $array = array(new TestElement('a'), new TestElement('b'), new TestElement('c'));
13 if (RSArrayUtil::hasElement($array, new TestElement('c'), new RSComparator())) {
14 echo 'c is contained in the array';
15 }
Returns true if the the array passed as first argument contains all elements of the array passed as second argument.
The comparison is handled by hasElement which uses http://www.php.net/in_array without type checking by default. An other comparison can be forced by passing an instance of the class RSComparator or a class that extends it.
Removes all duplicates from an array.
A new array with all duplicates removed is returned. The comparison is handled by hasElement which uses http://www.php.net/in_array without type checking by default. An other comparison can be forced by passing an instance of the class RSComparator or a class that extends it. This method iterates over the array passed as argument and copies all elements to the new array that are not already contained in it.
Returns a literal representation of an array.
This method is very flexible because it allows the programmer to specify the format of the key value pairs and the seperation character between these pairs. If the value is an object and has a toString method, that method is called to express the value of this array element.
Documentation generated on Mon, 8 Dec 2003 13:10:38 +0100 by phpDocumentor 1.2.3