-2

I'm trying to implement the min() function in my PHP code. The min value should be retried like this:

$ar=array($data[Price]);
echo min($ar);

The problem is that when I echo out $data[Price] I get my prices without commas nor spaces, so it becomes something like this:

$ar=array($data[Price]);
echo min(373945);  

But it should be:

echo min(37, 39, 45);

to get 37.

Is there any way to get comma separated values with implode?

My var_dump result of $data[Price]:

NULL 37.00NULL 39.00NULL 45.00
rink.attendant.6
  • 44,500
  • 61
  • 101
  • 156
user2635574
  • 195
  • 2
  • 6
  • 16

2 Answers2

0

Here's a short sample:

$array = array('lastname', 'email', 'phone');
foreach($array as &$value){
   $value = "'$value'";
}
$comma_separated = implode(",", $array);
Ali Gajani
  • 14,762
  • 12
  • 59
  • 100
0

I'm not quite sure what $data[Price] contains. If this is the value you get using var_dump, as you say:

NULL 37.00NULL 39.00NULL 45.00

You could do this:

$price = explode('NULL ', $data[Price]);
echo min($price);
federico-t
  • 12,014
  • 19
  • 67
  • 111