3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php // sample data $_SESSION["products"] = array(); $_SESSION["products"][] = array('vendorid'=>1, 'product_name'=>'TEST31' ); $_SESSION["products"][] = array('vendorid'=>4, 'product_name'=>'TEST21' ); $_SESSION["products"][] = array('vendorid'=>3, 'product_name'=>'TEST20' ); $_SESSION["products"][] = array('vendorid'=>3, 'product_name'=>'TEST17' ); $_SESSION["products"][] = array('vendorid'=>4, 'product_name'=>'TEST11' ); // actual code usort($_SESSION["products"], function($a, $b) { return $a['vendorid'] - $b['vendorid']; }); foreach( $_SESSION["products"] as $product ) { echo '<li>', htmlspecialchars($product['vendorid']), ' ', htmlspecialchars($product['product_name']), "</li>\r\n"; }
based on Z0ape
Output for 7.0.0 - 7.2.0
<li>1 TEST31</li> <li>3 TEST20</li> <li>3 TEST17</li> <li>4 TEST21</li> <li>4 TEST11</li>
Output for 5.5.0 - 5.6.28
<li>1 TEST31</li> <li>3 TEST17</li> <li>3 TEST20</li> <li>4 TEST11</li> <li>4 TEST21</li>