mirror of
https://github.com/EGroupware/egroupware.git
synced 2024-12-26 16:48:49 +01:00
Add array_pop(); test and confirm array_pop/array_shift; add comments to each
function; order functions alphabetically
This commit is contained in:
parent
38983d71cf
commit
3c70493ae1
@ -24,27 +24,10 @@
|
|||||||
|
|
||||||
/* $Id$ */
|
/* $Id$ */
|
||||||
|
|
||||||
function is_bool($var)
|
/* array_keys (PHP 4 >= 4.0.0)
|
||||||
{
|
* array array_keys (array input, mixed [search_value])
|
||||||
$retval = gettype($var) ;
|
* array_keys() returns the keys, numeric and string, from the input array.
|
||||||
if ( strcmp( $retval, 'unknown type') == 0 )
|
*/
|
||||||
{
|
|
||||||
/* Chances are that we have a boolean */
|
|
||||||
if ($var == True || $var == False)
|
|
||||||
{
|
|
||||||
return True;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
return False;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
return False ;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function array_keys ($arr, $term='')
|
function array_keys ($arr, $term='')
|
||||||
{
|
{
|
||||||
$t = array();
|
$t = array();
|
||||||
@ -59,7 +42,58 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/* array_pop (PHP 4 >= 4.0.0)
|
||||||
|
* mixed array_pop (array array)
|
||||||
|
* array_pop() pops and returns the last value of the array, shortening the array by
|
||||||
|
* one element. If array is empty (or is not an array), NULL will be returned.
|
||||||
|
*/
|
||||||
|
function array_pop(&$array)
|
||||||
|
{
|
||||||
|
if(!is_array($array) || @count($array) == 0)
|
||||||
|
{
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
reset($array);
|
||||||
|
$rtrn = array();
|
||||||
|
|
||||||
|
$i = count($array) + 1;
|
||||||
|
|
||||||
|
while(list($key,$value) = each($array))
|
||||||
|
{
|
||||||
|
$i--;
|
||||||
|
if($i == 1)
|
||||||
|
{
|
||||||
|
$last = $value;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$rtrn[$key] = $value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$array = $rtrn;
|
||||||
|
return $last;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* array_push
|
||||||
|
* int array_push (array array, mixed var [, mixed ...])
|
||||||
|
* array_push() treats array as a stack, and pushes the passed variables onto the end
|
||||||
|
* of array. The length of array increases by the number of variables pushed. Has the
|
||||||
|
* same effect as '$array[] = $var;' repeated for each var.
|
||||||
|
*/
|
||||||
|
/*
|
||||||
|
function array_push()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* array_reverse (PHP 4 >= 4.0.0)
|
||||||
|
* array array_reverse (array array [, bool preserve_keys])
|
||||||
|
* array_reverse() takes input array and returns a new array with the order of the
|
||||||
|
* elements reversed, preserving the keys if preserve_keys is TRUE.
|
||||||
|
* Note: The second parameter was added in PHP 4.0.3.
|
||||||
|
*/
|
||||||
|
/*
|
||||||
function array_reverse ($array, $preserve_keys = False)
|
function array_reverse ($array, $preserve_keys = False)
|
||||||
{
|
{
|
||||||
for(list($key,$value) = @end($array); list($key,$value) = @prev($array); )
|
for(list($key,$value) = @end($array); list($key,$value) = @prev($array); )
|
||||||
@ -68,8 +102,13 @@
|
|||||||
}
|
}
|
||||||
return $temp_array;
|
return $temp_array;
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
/* array_search (PHP 4 >= 4.0.5)
|
||||||
|
* mixed array_search (mixed needle, array haystack [, bool strict])
|
||||||
|
* Searches haystack for needle and returns the key if it is found in the array, FALSE
|
||||||
|
* otherwise.
|
||||||
|
*/
|
||||||
function array_search ($needle, $haystack, $strict = False)
|
function array_search ($needle, $haystack, $strict = False)
|
||||||
{
|
{
|
||||||
@reset($haystack);
|
@reset($haystack);
|
||||||
@ -83,26 +122,17 @@
|
|||||||
return False;
|
return False;
|
||||||
}
|
}
|
||||||
|
|
||||||
function in_array ($needle, $haystack, $strict = False)
|
/* array_shift (PHP 4 >= 4.0.0)
|
||||||
{
|
* mixed array_shift (array array)
|
||||||
if(is_array ($haystack) && count($haystack))
|
* array_shift() shifts the first value of the array off and returns it, shortening the
|
||||||
{
|
* array by one element and moving everything down. If array is empty (or is not an
|
||||||
for(@reset($haystack); $x=each($haystack); )
|
* array), NULL will be returned.
|
||||||
{
|
*/
|
||||||
if($needle==$x[1] && (!$strict || gettype($needle)==gettype($x[1])))
|
|
||||||
{
|
|
||||||
return True;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return False;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function array_shift(&$array)
|
function array_shift(&$array)
|
||||||
{
|
{
|
||||||
if(!is_array($array))
|
if(!is_array($array) || @count($array) == 0)
|
||||||
{
|
{
|
||||||
return '';
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
reset($array);
|
reset($array);
|
||||||
@ -125,6 +155,10 @@
|
|||||||
return $one;
|
return $one;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* array_unique (PHP 4)
|
||||||
|
* array array_unique (array array)
|
||||||
|
* array_unique() takes input array and returns a new array without duplicate values.
|
||||||
|
*/
|
||||||
function array_unique ($array)
|
function array_unique ($array)
|
||||||
{
|
{
|
||||||
reset($array);
|
reset($array);
|
||||||
@ -145,6 +179,67 @@
|
|||||||
return $new_array;
|
return $new_array;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* array_unshift (PHP 4 >= 4.0.0)
|
||||||
|
* int array_unshift (array array, mixed var, mixed [...])
|
||||||
|
* array_unshift() prepends passed elements to the front of the array. Note that the
|
||||||
|
* list of elements is prepended as a whole, so that the prepended elements stay in the
|
||||||
|
* same order. Returns the new number of elements in the array.
|
||||||
|
*/
|
||||||
|
/*
|
||||||
|
function array_unshift()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* in_array (PHP 4 >= 4.0.0)
|
||||||
|
* bool in_array (mixed needle, array haystack [, bool strict])
|
||||||
|
* Searches haystack for needle and returns TRUE if it is found in the array, FALSE
|
||||||
|
* otherwise.
|
||||||
|
*/
|
||||||
|
function in_array ($needle, $haystack, $strict = False)
|
||||||
|
{
|
||||||
|
if(is_array ($haystack) && count($haystack))
|
||||||
|
{
|
||||||
|
for(@reset($haystack); $x=each($haystack); )
|
||||||
|
{
|
||||||
|
if($needle==$x[1] && (!$strict || gettype($needle)==gettype($x[1])))
|
||||||
|
{
|
||||||
|
return True;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return False;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* is_bool (PHP 4 >= 4.0.0)
|
||||||
|
* bool is_bool (mixed var)
|
||||||
|
* is_bool -- Finds out whether a variable is a boolean
|
||||||
|
*/
|
||||||
|
function is_bool($var)
|
||||||
|
{
|
||||||
|
$retval = gettype($var) ;
|
||||||
|
if ( strcmp( $retval, 'unknown type') == 0 )
|
||||||
|
{
|
||||||
|
/* Chances are that we have a boolean */
|
||||||
|
if ($var == True || $var == False)
|
||||||
|
{
|
||||||
|
return True;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return False;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return False ;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* str_repeat (PHP 4 >= 4.0.0)
|
||||||
|
* string str_repeat (string input, int multiplier)
|
||||||
|
* Returns input_str repeated multiplier times. multiplier has to be greater than 0.
|
||||||
|
*/
|
||||||
function str_repeat($input,$multiplier)
|
function str_repeat($input,$multiplier)
|
||||||
{
|
{
|
||||||
for($i=0,$output='';$i<$multiplier;$i++)
|
for($i=0,$output='';$i<$multiplier;$i++)
|
||||||
|
Loading…
Reference in New Issue
Block a user