2001-08-16 08:32:22 +02:00
|
|
|
<?php
|
|
|
|
/**************************************************************************\
|
|
|
|
* phpGroupWare API - PHP3 Compatibility layer *
|
|
|
|
* This file written by Dan Kuykendall <seek3r@phpgroupware.org> *
|
2001-08-17 21:34:48 +02:00
|
|
|
* Has replications of PHP4 only functions to allow for transparent PHP3 *
|
2001-08-16 08:32:22 +02:00
|
|
|
* compatibility *
|
|
|
|
* Copyright (C) 2000, 2001 Dan Kuykendall *
|
|
|
|
* -------------------------------------------------------------------------*
|
|
|
|
* This library is part of the phpGroupWare API *
|
|
|
|
* http://www.phpgroupware.org/api *
|
|
|
|
* ------------------------------------------------------------------------ *
|
|
|
|
* This library is free software; you can redistribute it and/or modify it *
|
|
|
|
* under the terms of the GNU Lesser General Public License as published by *
|
|
|
|
* the Free Software Foundation; either version 2.1 of the License, *
|
|
|
|
* or any later version. *
|
|
|
|
* This library is distributed in the hope that it will be useful, but *
|
|
|
|
* WITHOUT ANY WARRANTY; without even the implied warranty of *
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. *
|
|
|
|
* See the GNU Lesser General Public License for more details. *
|
|
|
|
* You should have received a copy of the GNU Lesser General Public License *
|
|
|
|
* along with this library; if not, write to the Free Software Foundation, *
|
|
|
|
* Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA *
|
|
|
|
\**************************************************************************/
|
|
|
|
|
2001-11-23 18:24:49 +01:00
|
|
|
/* $Id$ */
|
|
|
|
|
2001-08-16 08:32:22 +02:00
|
|
|
function is_bool($var)
|
|
|
|
{
|
|
|
|
$retval = gettype($var) ;
|
2001-11-23 18:24:49 +01:00
|
|
|
if ( strcmp( $retval, 'unknown type') == 0 )
|
2001-08-16 08:32:22 +02:00
|
|
|
{
|
|
|
|
/* Chances are that we have a boolean */
|
|
|
|
if ($var == True || $var == False)
|
|
|
|
{
|
|
|
|
return True;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return False;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return False ;
|
|
|
|
}
|
|
|
|
}
|
2001-08-17 21:34:48 +02:00
|
|
|
|
2001-11-23 18:24:49 +01:00
|
|
|
function array_keys ($arr, $term='')
|
2001-11-10 21:48:43 +01:00
|
|
|
{
|
|
|
|
$t = array();
|
|
|
|
while (list($k,$v) = each($arr))
|
|
|
|
{
|
|
|
|
if ($term && $v != $term)
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
$t[] = $k;
|
|
|
|
}
|
|
|
|
return $t;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-08-17 21:34:48 +02:00
|
|
|
/*
|
2001-11-23 18:24:49 +01:00
|
|
|
function array_reverse ($array, $preserve_keys = False)
|
2001-08-17 21:34:48 +02:00
|
|
|
{
|
|
|
|
for(list($key,$value) = @end($array); list($key,$value) = @prev($array); )
|
|
|
|
{
|
|
|
|
$temp_array[$key] = $value;
|
|
|
|
}
|
|
|
|
return $temp_array;
|
|
|
|
}
|
|
|
|
*/
|
|
|
|
|
2001-11-23 18:24:49 +01:00
|
|
|
function array_search ($needle, $haystack, $strict = False)
|
2001-08-17 21:34:48 +02:00
|
|
|
{
|
|
|
|
@reset($haystack);
|
|
|
|
while(list($key,$value) = each($haystack))
|
|
|
|
{
|
2001-08-21 18:51:21 +02:00
|
|
|
if ($haystack[$key]==$needle && (!$strict || gettype($haystack[$key])==gettype($needle)))
|
2001-08-17 21:34:48 +02:00
|
|
|
{
|
|
|
|
return $key;
|
|
|
|
}
|
|
|
|
}
|
2001-11-23 18:24:49 +01:00
|
|
|
return False;
|
2001-08-17 21:34:48 +02:00
|
|
|
}
|
|
|
|
|
2001-11-23 18:24:49 +01:00
|
|
|
function in_array ($needle, $haystack, $strict = False)
|
2001-08-17 21:34:48 +02:00
|
|
|
{
|
|
|
|
if(is_array ($haystack) && count($haystack))
|
|
|
|
{
|
|
|
|
for(@reset($haystack); $x=each($haystack); )
|
|
|
|
{
|
|
|
|
if($needle==$x[1] && (!$strict || gettype($needle)==gettype($x[1])))
|
|
|
|
{
|
2001-11-23 18:24:49 +01:00
|
|
|
return True;
|
2001-08-17 21:34:48 +02:00
|
|
|
}
|
|
|
|
}
|
2001-11-23 18:24:49 +01:00
|
|
|
return False;
|
2001-08-17 21:34:48 +02:00
|
|
|
}
|
|
|
|
}
|
2001-08-21 02:16:36 +02:00
|
|
|
|
2001-12-24 19:05:56 +01:00
|
|
|
function array_unique ($array)
|
|
|
|
{
|
|
|
|
reset($array);
|
|
|
|
$reversed_array = Array();
|
|
|
|
while(list($key,$value) = each($array))
|
|
|
|
{
|
|
|
|
if (!isset($reversed_array[$value]))
|
|
|
|
{
|
|
|
|
$reversed_array[$value] = $key;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
unset($key, $value);
|
|
|
|
while(list($key,$value) = each($reversed_array))
|
|
|
|
{
|
|
|
|
$new_array[$key] = $value;
|
|
|
|
}
|
|
|
|
return $new_array;
|
|
|
|
}
|
|
|
|
|
2001-08-21 02:16:36 +02:00
|
|
|
function str_repeat($input,$multiplier)
|
|
|
|
{
|
|
|
|
for($i=0,$output='';$i<$multiplier;$i++)
|
|
|
|
{
|
|
|
|
$output .= $input;
|
|
|
|
}
|
|
|
|
return $output;
|
|
|
|
}
|
2001-08-17 21:34:48 +02:00
|
|
|
?>
|