Here's a short sample:
$array = array('lastname', 'email', 'phone');
foreach($array as &$value){
$value = "'$value'";
}
$comma_separated = implode(",", $array);
Pregunta
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
Solución
Here's a short sample:
$array = array('lastname', 'email', 'phone');
foreach($array as &$value){
$value = "'$value'";
}
$comma_separated = implode(",", $array);
Otros consejos
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);