Page 1 of 1

logic inside of an array?

Posted: Thu Oct 18, 2007 5:57 pm
by imimin
I need help in getting a php script I have been working on for a while finished. I came to a stopping point (brick wall) today when I tried to execute flow control inside of an array. Can someone please tell me if it is possible to use logic inside of an array?

An example of what I would like to do is:

Code: Select all

$shippingCost = $baseShippingCost * $shippingBoxArr['numberOfBoxes'];
$shippingBoxArr is an arrray and I would like to apply the following logic while the array runs, but am not sure how to do it:

Code: Select all

if ($endTotalShippingCost = ('$dryIceCost + $totBoxCost + $ups_res_charge + $ups_dist_charge')) {$endTotalShippingCost=1000000;}
	
else {$endTotalShippingCost=$endTotalShippingCost;}
I would appreciate any help I can get on this!

Posted: Thu Oct 18, 2007 7:30 pm
by imimin
What I mean by
"while the array 'runs'."
is when the array code executes I would like to apply some logic to the array values (I am not sure if this is possible or if i should take a different approach).

Posted: Thu Oct 18, 2007 7:45 pm
by califdon
An array is just a temporary data storage, there is no "logic" or "code" inherent in it. You can certainly apply logic as you fill the array with data values, which may be what you're thinking about.

Posted: Thu Oct 18, 2007 8:15 pm
by VladSun
I can't understand it either, but perhaps you are looking for array_walk or array_map functions.