@ 2015-11-10T21:57:36Z <?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));
$cnt = 0;
foreach($products as $pkey=>$pobj) {
foreach($carts as $ckey=>$carray) {
if(isset($carray['chemID']) && isset($pobj['chemID']) && $carray['chemID']==$pobj['chemID']) {
if(isset($carray['catID']) && isset($pobj['catID']) && $carray['catID']==$pobj['catID']) {
$cnt++;
}
}
}
}
echo $cnt;
Enable javascript to submit You have javascript disabled. You will not be able to edit any code.
Output for 7.0.0 - 7.0.20 , 7.1.0 - 7.1.25 , 7.2.0 - 7.2.33 , 7.3.0 - 7.3.33 , 7.4.0 - 7.4.33 , 8.0.0 - 8.0.30 , 8.1.0 - 8.1.28 , 8.2.0 - 8.2.18 , 8.3.0 - 8.3.6 Fatal error: Uncaught Error: Cannot use object of type Products as array in /in/dpmuh:22
Stack trace:
#0 {main}
thrown in /in/dpmuh on line 22
Process exited with code 255 . Output for 5.5.24 - 5.5.35 , 5.6.8 - 5.6.28 Fatal error: Cannot use object of type Products as array in /in/dpmuh on line 22
Process exited with code 255 . preferences:dark mode live preview
155.5 ms | 402 KiB | 197 Q