Multidimensional Arrays & foreach....loop? in PHP Coding Help Posted February 25, 2013 · Edited February 25, 2013 by sraj Hi , Could you please help me to sort the array of array['laser'] to top. Thank in advance. <?php $products = array( 'paper' => array( 'copier' => "Copier & Multipurpose", 'inkjet' => "Inkjet Printer", 'laser' => "Laser Printer", 'photo' => "Photographic Paper"), 'pens' => array( 'copier' => "Ball Point", 'inkjet' => "Highlighters", 'laser' => "Markers", 'photo' => "Protection")), 'misc' => array( 'copier' => "Sticky Tape", 'inkjet' => "Adhesives", 'laser' => "Sweet", 'photo' => "Protection")); echo "<pre>"; foreach ($products as $section => $items ) foreach ($items as $key => $value) echo "$section:\t$key\t($value)<br>"; echo "</pre>"; ?>
Multidimensional Arrays & foreach....loop?
in PHP Coding Help
Posted · Edited by sraj
Hi ,
Could you please help me to sort the array of array['laser'] to top. Thank in advance.
<?php
$products = array(
'paper' => array(
'copier' => "Copier & Multipurpose",
'inkjet' => "Inkjet Printer",
'laser' => "Laser Printer",
'photo' => "Photographic Paper"),
'pens' => array(
'copier' => "Ball Point",
'inkjet' => "Highlighters",
'laser' => "Markers",
'photo' => "Protection")),
'misc' => array(
'copier' => "Sticky Tape",
'inkjet' => "Adhesives",
'laser' => "Sweet",
'photo' => "Protection"));
echo "<pre>";
foreach ($products as $section => $items )
foreach ($items as $key => $value)
echo "$section:\t$key\t($value)<br>";
echo "</pre>";
?>