Re: Array Help Needed



"J.O. Aho" <user@xxxxxxxxxxx> wrote in message
news:6nskulFn2sbU1@xxxxxxxxxxxxxxxxxxxxx
Jerry wrote:

// pull subscriptions
$subscriptions = array();

$tot_sum = 0;
$add_this = false;
foreach ($order->products as $product) {
foreach ($product['attributes'] as $attribute) {
if ($attribute['option'] == 'Subscription') {
$subscriptions[] = $product;
if(isset($product['final_price']))
$add_this = true;
}
}
if($add_this) {
$tot_sum += $product['final_price'];
$add_this = false;
}
}

As a follow up question do you know how I could do the following:

Get all the [final_price] from the array that are from [attributes]
[option]
== 'Subscription' and add them into a total sum.

See above.

You need to make a check in the inner loop, and assing the value in the
outer,
in case the the attribute array is larger than one cell. In case it never
will, you could skip that array completely in your design.

--

//Aho


That is a nice solution! Thanks again J.O. Aho.

Best Regards, Jerry


.



Relevant Pages

  • Re: Array Help Desired
    ... foreach ... 'Subscription' and add them into a total sum. ... use conditions to add to the total price when appropriate. ...
    (comp.lang.php)
  • Re: Array Help Needed
    ... // pull subscriptions ... foreach { ... you could skip that array completely in your design. ...
    (alt.php)
  • Re: Array Help Needed
    ... // pull subscriptions ... foreach ... I have an array of ORDER DETAILS. ...
    (alt.php)
  • Re: Array Help Desired
    ... foreach ... Sorry, Jerry. ... Hope it got you started on the right foot. ...
    (comp.lang.php)
  • old sysmergesubscriptions records
    ... We have a replication system with hundreds of merge pull subscriptions ... that have appeared in the sysmergesubscriptions tables all over the place. ... The push subscriptions are all subscribing from and to the same server name, ... It also has two local pull subscriptions to TESTNET-SERVER which i want to ...
    (microsoft.public.sqlserver.programming)