Why doesn't working with array's ever stick in my thick head?

From: Date: Fri, 09 May 2008 16:56:13 +0000
Subject: Why doesn't working with array's ever stick in my thick head?
Groups: php.general 
Request: Send a blank email to php-general+get-274083@lists.php.net to get a copy of this message
Hi Everyone, SO it's friday, I'm tired, and I can't seem to think straight... I am attempting to do some very basic math with some arrays... Here's the pseudo code that I'm working with: NumberOfPieces * PieceWeight = TotalWeight explode total weight to get tenth's of pounds, then divide tenth's of pounds by 16 to grab ounces. Display TotalWeight # Exploded Ounces. Which I have working just fine for a single set of boxes... My problem is I want to be able to automatically add say 50 boxes in a form to process the weight of each route... So what I need to do is probably use some kind of a counter to loop through my $RoutePieces array and multiply by the $PieceWeight? $PieceWeight is a static number. Now let me show you some abbreviated code to try and explain what I'm using right now: <?PHP $i= "0"; $num= "2"; $PieceWeight = $_POST['txtPieceWeight']; $RoutePieces[] = $_POST['txtRoutePieces']; $RouteNumber[] = $_POST['txtRoute']; $totalWeight = $PieceWeight * $RoutePieces/16; $weightExplode = explode('.', $totalWeight); //$weightOunces = ((float)('.' . $weightExplode[1])) * 16; // Use stut's method... Seems cleaner $explodeOunces = ($totalWeight - intval($totalWeight)) * 16; while($i <= $num){ echo <<<HTML <p> Route Number:<input type="text" name="txtRoute[$i]" size="4" value ="{$RouteNumber[$i]}"> Number of pieces: <input type="text" name="txtRoutePieces[$i]" size="4" value="{$RoutePieces[$i]}"><label>Total weight of route: {$weightExplode[0]} # {$explodeOunces} Ounces</label> </p> HTML; $i++; echo $i; } ?> the $_POST array has the proper values stored properly... I just can't seem to figure out how to work with the values... Any ideas? Or slaps on the back of the head to wake me up a little? :) I need help :P -- Jason Pruim Raoset Inc. Technology Manager MQC Specialist 3251 132nd ave Holland, MI, 49424-9337 www.raoset.com japruim@raoset.com

« previous php.general (#274083) next »