Laravel 4 foreach loop - wanting to display the last element -


i trying set edit page order form populated using json_decode decode json information saved when form created. because form's size can change have create correct number of inputs json data have place displayed. fortunately inputs numbered should not hard do. unfortunately not sure how pick last element of json information has been decoded. using:

public function getedit($id){         $order = order::where('id', '=', $id);          if($order->count()) {             $order                      = $order->first();             $order->order_serialized    = json_decode($order->order_serialized);              foreach($order->order_serialized $key => $value){                 $order->$key = $value;             }             return view::make('orders.edit')                     ->with('order', $order);         }   else {             return app::abort(404);         }     } 

to decode information , working splendidly need able pick last element able find total number of inputs , not sure how without disturbing foreach loop. , appreciated!! thank much!

you can use count , toarray methods find last item.

$nitem = $order->count(); $aorder = $order->toarray(); $alastitem = $aorder[$nitem-1]; 

Comments

Popular posts from this blog

php - Magento - Deleted Base url key -

javascript - Tooltipster plugin not firing jquery function when button or any click even occur -

java - WrongTypeOfReturnValue exception thrown when unit testing using mockito -