View Full Version : formatting all int values of an array
sabret00the
06-23-2005, 04:58 PM
would this be the best way to do it, or do you know a better way to do it?
foreach($array AS $key => $value)
{
if (intval($value))
{
$array[] = vb_number_format($this->GetStats[$value]);
}
else
{
$array[] = $value;
}
}
calorie
06-23-2005, 05:29 PM
What do you want to have happen when...
$value = 1000.01;
$value = 0;
$value = '1a';
$value = '';
sabret00the
06-23-2005, 05:31 PM
1,000,000 or whatever the vb_number_format() is set at via the $vboptions.
calorie
06-23-2005, 05:41 PM
foreach($array AS $key => $value)
{
$value = intval($value);
$array[] = ($value > 999) : vb_number_format($this->GetStats[$value]) ? $value;
}
sabret00the
06-23-2005, 05:51 PM
the only problem with that is that the $value could be 1, 5, 1million or 1billion, also in the array theirs also string values which don't need to be number formatted.
calorie
06-23-2005, 05:57 PM
foreach($array AS $key => $value)
{
if (is_numeric($value))
{
$value = intval($value);
$array[] = ($value > 999) : vb_number_format($this->GetStats[$value]) ? $value;
}
else
{
$array[] = $value;
}
}
sabret00the
06-23-2005, 06:04 PM
ahhh is_numeric was the function i was looking for, thank you calorie :)
vBulletin® v3.8.12 by vBS, Copyright ©2000-2024, vBulletin Solutions Inc.