php - MAX numeric value from mixed array -


i have array contains both strings , numeric values, while using code keep getting highest string value, how numeric max values array?

$maxprice = max($textpieces); 

i have tried returns number of keys in array

 $maxprice = max(array_search($textpieces)); 

thanks help! have looked max function here not give information http://php.net/manual/en/function.max.php

i have looked @ solution find highest max() of mixed array possible without building custom function?

$maxprice = max(array_filter($textpieces, 'is_numeric')); 

it @ first filters entries contains digits (integers) , extracts max() it

the following solution:

$max = array_reduce($textpieces, function($max, $i) {     if (is_numeric($i) && $i > $max) {         return $i;     }      return $max; });  var_dump($max); 

could bit more performance (from both cpu , memory perspectives) more complicated well.


Comments

Popular posts from this blog

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -

javascript - firefox memory leak -

Trying to import CSV file to a SQL Server database using asp.net and c# - can't find what I'm missing -