php - Print Array Key Multidimensional within a Foreach -


i have array (getting data excel file) have been trying "merge" data dependent on id. have managed create array (grouping products id), results in following.

array ( [order10] => array ( [mr name] => array ( [45 street] => array ( [area] => array ( [product1] => 1 [product2] => 3 ) ) ) ) ) 

i trying to data extracted (order, name, street etc.), managing extract id (order10) using key(var). here basic layout of code like.

//gets data excel file foreach ($bulk $prod) {     $apiorder[] = array('order' => $prod['order'],                          'prod' => $prod['prod'],                         'quantity' => $prod['qty'],                         'recipient_name' => $prod['recipient_name']); }  $newoptions = array(); foreach ($apiorder $option) {     $order = $option['order'];     $prod = $option['prod'];     $qty = $option['quantity']; //added     $recipient_name = $option['recipient_name'];     $newoptions[$order][$recipient_name][$prod] = $qty; }  $index4 = 0;  foreach($newoptions $key=>$val) {     $seperateoptions = (array_slice($newoptions, $index4, true));     //print array check, echo id, name, product     $index4++; } 

i can data extracted if not have code within foreach loop. problem order repeated depending on how many products on order, makes inserting order database system abit harder. below example:

array ( [order10] => array ( [mr name] => array ( [45 street] => array ( [area] => array ( [product1] => 1) ) ) ) ) array ( [order10] => array ( [mr name] => array ( [45 street] => array ( [area] => array ( [product2] => 3) ) ) ) ) 

as have said, can extract data if don't try put products within array, have create loop when data being sent database add missing products. sort of direction appreciated.

this not answer, based on comments between op , me, try show him, how , it's long, , here code formatting. key id of order, everyhing in array has more 1 value. products array too. try keep related things enclosed.:

$orders = [     'order10' => [         'name' => 'mr name',         'address' => [             'street' => 'street here',             'country' => 'country here',             'zipcode' => 'zipcode here'         ],         'phones' => [             'mobile' => 'mobile phone here',             'fax' => 'fax here',             'workplace' => 'here'         ],         'products' => [             'productid1',             'productid2',             //and on         ]     ] ]; 

and can iterate order array show:

foreach ($orders $order) {         ?>         <div>name: <?php echo $order['name']; ?></div>         <div>address: <?php echo $order['address']['zipcode']; ?>, <?php echo $order['address']['country']; ?>, <?php echo $order['address']['street']; ?>    </div>         <div>products:              <?php             foreach ($order['products'] $procutid) {                 $produt = new procut($productid);                 ?>                 <div><?php echo $product->getname(); ?></div>                 <?php             }             ?>         </div>         <hr>         <?php     } } ?> 

in example, have product class, maybe not using classes, of course, can create getprocut($id) function product id, be

$product = getproduct($procutid); echo $product['name']; 

this decision.


Comments

Popular posts from this blog

javascript - Laravel datatable invalid JSON response -

java - Exception in thread "main" org.springframework.context.ApplicationContextException: Unable to start embedded container; -

sql server 2008 - My Sql Code Get An Error Of Msg 245, Level 16, State 1, Line 1 Conversion failed when converting the varchar value '8:45 AM' to data type int -