mysql - PHP Add more value to foreach for display group by vendor -


how add more value code display?

ex : added 5 products cart different vendors.

p1 vendor name test1 p2 , p3 vendor name test2 p4 vendor name test3 p5 vendor name test4 

my code :

function getvendors() {   foreach($_session["products"] $product) {     $org[$product["member_display_name"]][]   =   $product["p_name"];   }   return (!empty($org)) ? $org : array(); }  foreach (getvendors() $vendor => $prods) {   echo "<li>vendor name : {$vendor} </li>";   echo "<li>" . implode("</li><li>",$prods) . "</li>"; } 

this code given output like:

vendor name : test1 p1 vendor name : test2 p2 p3 vendor name : test3 p4 vendor name : test4 p5 

this want

i want add $product["member_payment"] display :

vendor name : test1 p1 payment vendor : 000-111-111 vendor name : test2 p2 p3 payment vendor : 000-111-222 vendor name : test3 p4 payment vendor : 000-111-333 vendor name : test4 p5 payment vendor : 000-111-444 

imho need restructure array bit. add pair of keys inside $org, can access iterator

function getvendors() {     foreach($_session["products"] $product) {         $org[$product["member_display_name"]]['product'][]   =   $product["p_name"];     }     $org[$product["member_display_name"]]['payment'] = $product["p_payment"]; //where $product['p_payment'] string '000-111-222'      return (!empty($org))? $org : array();  }  foreach(getvendors() $vendor => $prods) {     echo "<li>vendor name : {$vendor} </li>";     if (isset($prods['product'])) echo "<li>".implode("</li><li>",$prods['product'])."</li>";     if (isset($prods['payment'])) echo "<li>payment vendor : ".$prods['payment']."</li>"; } 

i'm answering & typing above head.. hoping general idea.


Comments

Popular posts from this blog

get url and add instance to a model with prefilled foreign key :django admin -

css - Make div keyboard-scrollable in jQuery Mobile? -

ruby on rails - Seeing duplicate requests handled with Unicorn -