I am working with PHP arrays and objects. I have been working with them for quite a while now. However, I am stuck at a problem, which might have a really simple solution.
I have a variable $products inside a function which receives value on call. I am trying to count the objects in the variable to see how many products are inside it. I tried the simple count($products) and count((array)$products) function and it isn't working. I know that isn't the best way to count the objects.
Is there any way to count them?
object(stdClass)#46 (3) {
["0"]=>
object(stdClass)#47 (1) {
["productid"]=>
string(2) "15"
}
["1"]=>
object(stdClass)#48 (1) {
["productid"]=>
string(2) "16"
}
["2"]=>
object(stdClass)#48 (1) {
["productid"]=>
string(2) "26"
}
}
I need this to return 3
object(stdClass)#20 (1) {
["productid"]=>
string(2) "21"
}
I need this to return 1