note 110279 added to function.array-values
| From: | espertalhao04 at hotmail dot com | Date: | Sun, 07 Oct 2012 04:47:54 +0000 |
| Subject: | note 110279 added to function.array-values | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-191169@lists.php.net to get a copy of this message | ||
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
?>
----
Server IP: 69.147.83.199
Probable Submitter: 85.240.223.178
----
Manual Page -- http://www.php.net/manual/en/function.array-values.php
Edit -- https://master.php.net/note/edit/110279
Del: integrated -- https://master.php.net/note/delete/110279/integrated
Del: useless -- https://master.php.net/note/delete/110279/useless
Del: bad code -- https://master.php.net/note/delete/110279/bad+code
Del: spam -- https://master.php.net/note/delete/110279/spam
Del: non-english -- https://master.php.net/note/delete/110279/non-english
Del: in docs -- https://master.php.net/note/delete/110279/in+docs
Del: other reasons-- https://master.php.net/note/delete/110279
Reject -- https://master.php.net/note/reject/110279
Search -- https://master.php.net/manage/user-notes.php