foreach if else
-
I Have a issue using a mvc type plugin (groupbuying if anyone else uses)
In the controller for the cart view i have these
$line_items = array( 'subtotal' => array( 'label' => self::__( 'Subtotal' ), 'data' => gb_get_formatted_money( $cart->get_subtotal() ), 'weight' => 10, ), 'discount' => array('label' => self::__( 'Facebook Discount @100%') , 'data' => gb_get_formatted_money( $facebookdisc ), 'weight' => 11, ), 'total' => array( 'label' => self::__( 'Total' ), 'data' => gb_get_formatted_money( $cart->get_total() ), 'weight' => 1000, ), ); $line_items = apply_filters( 'gb_cart_line_items', $line_items, $cart ); uasort( $line_items, array( get_class(), 'sort_by_weight' ) );and then in the view
<tbody> <?php foreach ( $items as $item ): ?> <tr class="cart-line-item-row-<?php esc_attr_e( $key ); ?>"> <?php foreach ( $columns as $key => $label ): ?> <td class="cart-<?php esc_attr_e( $key ); ?>"> <?php if ( isset( $item[$key] ) ) { echo $item[$key]; } ?> </td> <?php endforeach; ?> </tr> <?php endforeach; ?> <?php foreach ( $line_items as $key => $line ) : //issues here! if ( $line['weight'] = 11) : ?> <tr class="cart-line-item cart-line-item-row-<?php esc_attr_e($key); ?>"> <th scope="row" colspan="<?php echo count($columns)-1; ?>"><?php esc_html_e( $line['label'] ); ?></th> <td class="cart-line-item-<?php esc_attr_e($key); ?>"><?php esc_html_e($line['data']); ?></td> </tr> <?php ; else : ?> <tr> this sucks </tr> <?php endif; ?> <?php endforeach; ?> </tbody>The issues occur on the 2nd foreach statement.
If i use just the if statement, all the $lines will show, if i include the else statement it doesn’t print the line which i gather to mean its seeing all the weights as 11 or i’ve mucked up somewhere!
Anyone any ideas of why its not working (BTW if i take out the if statement altogether it prints all the $line_items)
Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
The topic ‘foreach if else’ is closed to new replies.