3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php $products = array(); class Products { public $chemID; public $catID; } $prod1 = new Products; $prod1->chemID=1; $prod1->catID=1; array_push($products,$prod1); for($i = 1; $i < 5; $i++) { ${'prod'.$i} = new Products; ${'prod'.$i}->chemID = $i; ${'prod'.$i}->catID = $i; array_push($products,${'prod'.$i}); } $carts = (object)array(array("chemID"=> 1, "catID" => 4),array("chemID"=> 2, "catID" => 4), array("chemID"=> 1, "catID" => 1)); var_dump($carts); foreach($products as $pkey=>$pobj) { foreach($carts as $ckey=>$cvalue) { echo $ckey . ' ' .$cvalue; } }
based on 2lMVE
Output for 7.2.0
object(stdClass)#6 (3) { ["0"]=> array(2) { ["chemID"]=> int(1) ["catID"]=> int(4) } ["1"]=> array(2) { ["chemID"]=> int(2) ["catID"]=> int(4) } ["2"]=> array(2) { ["chemID"]=> int(1) ["catID"]=> int(1) } } Notice: Array to string conversion in /in/v3iOA on line 22 0 Array Notice: Array to string conversion in /in/v3iOA on line 22 1 Array Notice: Array to string conversion in /in/v3iOA on line 22 2 Array Notice: Array to string conversion in /in/v3iOA on line 22 0 Array Notice: Array to string conversion in /in/v3iOA on line 22 1 Array Notice: Array to string conversion in /in/v3iOA on line 22 2 Array Notice: Array to string conversion in /in/v3iOA on line 22 0 Array Notice: Array to string conversion in /in/v3iOA on line 22 1 Array Notice: Array to string conversion in /in/v3iOA on line 22 2 Array Notice: Array to string conversion in /in/v3iOA on line 22 0 Array Notice: Array to string conversion in /in/v3iOA on line 22 1 Array Notice: Array to string conversion in /in/v3iOA on line 22 2 Array Notice: Array to string conversion in /in/v3iOA on line 22 0 Array Notice: Array to string conversion in /in/v3iOA on line 22 1 Array Notice: Array to string conversion in /in/v3iOA on line 22 2 Array
Output for 5.4.9 - 7.1.10
object(stdClass)#6 (3) { [0]=> array(2) { ["chemID"]=> int(1) ["catID"]=> int(4) } [1]=> array(2) { ["chemID"]=> int(2) ["catID"]=> int(4) } [2]=> array(2) { ["chemID"]=> int(1) ["catID"]=> int(1) } } Notice: Array to string conversion in /in/v3iOA on line 22 0 Array Notice: Array to string conversion in /in/v3iOA on line 22 1 Array Notice: Array to string conversion in /in/v3iOA on line 22 2 Array Notice: Array to string conversion in /in/v3iOA on line 22 0 Array Notice: Array to string conversion in /in/v3iOA on line 22 1 Array Notice: Array to string conversion in /in/v3iOA on line 22 2 Array Notice: Array to string conversion in /in/v3iOA on line 22 0 Array Notice: Array to string conversion in /in/v3iOA on line 22 1 Array Notice: Array to string conversion in /in/v3iOA on line 22 2 Array Notice: Array to string conversion in /in/v3iOA on line 22 0 Array Notice: Array to string conversion in /in/v3iOA on line 22 1 Array Notice: Array to string conversion in /in/v3iOA on line 22 2 Array Notice: Array to string conversion in /in/v3iOA on line 22 0 Array Notice: Array to string conversion in /in/v3iOA on line 22 1 Array Notice: Array to string conversion in /in/v3iOA on line 22 2 Array
Output for 5.3.19 - 5.3.29
object(stdClass)#6 (3) { [0]=> array(2) { ["chemID"]=> int(1) ["catID"]=> int(4) } [1]=> array(2) { ["chemID"]=> int(2) ["catID"]=> int(4) } [2]=> array(2) { ["chemID"]=> int(1) ["catID"]=> int(1) } } 0 Array1 Array2 Array0 Array1 Array2 Array0 Array1 Array2 Array0 Array1 Array2 Array0 Array1 Array2 Array