note 110278 deleted from language.types.float by danbrown
| From: | danbrown@php.net | Date: | Wed, 17 Oct 2012 21:25:51 +0000 |
| Subject: | note 110278 deleted from language.types.float by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-191395@lists.php.net to get a copy of this message | ||
Note Submitter: Anonymous
----
i have created a FULLY MIXED max function!!!
it uses someone else's code, so, credits for them!!!
grycsys at gmail dot com --> thank you for your tiny piece of demonstration, you made this being
possible for floats!!!
kapilgopinath at gmail dot com --> thank you for creating this tiny and simple function to get
the values from recursive AND associative arrays!!!
here is the function:
<?php
/*mixed function created by me!!!
*parameters:
*str: the string (float and decimal int) OR ARRAY to check for the maximum value
*del: splits the string into an array, divided by this defined char
*returns: NULL if nothing was found, string with the highest value
*check examples below
*/
function max_mix($str="",$del="")
{
$c=((is_array( $str=(($del=( (is_array($str))?"":$del ) )?explode($del,$str):$str))
)?count($str=@array_keys_multi($str)):strlen($str))-1;
for($i=0;$i<=$c;$i++)
{
@$max=(( (is_float($str[$i])?(float)(string)$str[$i]:$str[$i]) >$max)?$str[$i]:$max);
}
return (((string)$max)?(string)$max:NULL);
}
//function created by kapilgopinath at gmail dot com
//simply provide the array and use @ before calling this function!!!
function array_keys_multi($array,&$vals)
{
foreach ($array as $key => $value) {
if (is_array($value)) {
array_keys_multi($value,$vals);
}else{
$vals[] = $value;
}
}
return $vals;
}
echo
max_mix(array("dog","cat",array("mouse")),",");//returns
mouse (idiot proof!!! doesn't try to explode an array!!!)
echo max_mix("a.5,7.9,3á,á3",",");//returns á3
echo max_mix("1234567890");//returns 9
echo max_mix("1a2b3c4d5e6f7g8h9i");//returns i
?>