using explode

This is a discussion on using explode within the PHP General forums, part of the PHP Programming Forums category; Hi everyone, I am wondering if I can write this cleaner? $weightExplode = explode(".", $totalWeight); $explodetest = "."; $explodetest .= $...


Go Back   Usenet Forums > PHP Programming Forums > PHP General

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 05-05-2008
Jason Pruim
 
Posts: n/a
Default using explode

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?

--

Jason Pruim
Raoset Inc.
Technology Manager
MQC Specialist
3251 132nd ave
Holland, MI, 49424-9337
www.raoset.com
japruim@raoset.com




Reply With Quote
  #2 (permalink)  
Old 05-05-2008
Zoltán Németh
 
Posts: n/a
Default Re: [PHP] using explode

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
> japruim@raoset.com
>
>
>
>


Reply With Quote
  #3 (permalink)  
Old 05-05-2008
Stut
 
Posts: n/a
Default Re: [PHP] using explode

On 5 May 2008, at 20:04, Jason Pruim wrote:
> 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...


$explodetest = ($totalWeight - intval($totalWeight)) * 16;

Untested but should have the same effect as your code.

-Stut

--
http://stut.net/
Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +1. The time now is 06:10 AM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0