logic inside of an array?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
imimin
Forum Commoner
Posts: 38
Joined: Thu Oct 18, 2007 5:44 pm

logic inside of an array?

Post 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!
imimin
Forum Commoner
Posts: 38
Joined: Thu Oct 18, 2007 5:44 pm

Post 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).
User avatar
califdon
Jack of Zircons
Posts: 4484
Joined: Thu Nov 09, 2006 8:30 pm
Location: California, USA

Post 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.
User avatar
VladSun
DevNet Master
Posts: 4313
Joined: Wed Jun 27, 2007 9:44 am
Location: Sofia, Bulgaria

Post by VladSun »

I can't understand it either, but perhaps you are looking for array_walk or array_map functions.
There are 10 types of people in this world, those who understand binary and those who don't
Post Reply