October 25, 2024
Chicago 12, Melborne City, USA
PHP

getting a php error on isset() for multidimentional array


I am getting a php error on this line

if (isset($this->contents[$products_id])) {

my function:

class shoppingCart {
    public ?array $contents = null;

function get_quantity($products_id) {
      if (isset($this->contents[$products_id])) {
        return $this->contents[$products_id]['qty'];
      } else {
        return 0;
      }
}
}

The array is defined public, yet it seems to be undefined, or at least a problem when empty?

Thanks for any thoughts!



You need to sign in to view this answers

Leave feedback about this

  • Quality
  • Price
  • Service

PROS

+
Add Field

CONS

+
Add Field
Choose Image
Choose Video