Re: [PHP] using explode

[email protected] (Zoltán Németh)
Newsgroups php.general
Message-ID <[email protected]>
Jason Pruim írta:
> Hi everyone,
> 
> I am wondering if I can write this cleaner?
>     $weightExplode = explode(".", $totalWeight);
>     $explodetest = ".";
>     $explodetest .= $weightExplode[1];
>     $explodetest = $explodetest*16;
> 
> 
> I'm hoping I've missed something... Basically I just need to include the 
> "." in $weightExplode[1] before I multiply it by 16. That's the only 
> part that is confusing me right now...
> 
> Any ideas?

I can't write it cleaner, though I can write it shorter:

$weightExplode = explode('.', $totalWeight);
$explodetest = ((float)('.' . $weightExplode[1])) * 16;

(the (float) casting is maybe not required, but I think it's good practice)

greets,
Zoltán Németh

> 
> -- 
> 
> Jason Pruim
> Raoset Inc.
> Technology Manager
> MQC Specialist
> 3251 132nd ave
> Holland, MI, 49424-9337
> www.raoset.com
> [email protected]
> 
> 
> 
>
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.