PHP note: using type undefined constant

I am doing something wrong and I canโ€™t figure out what to do with it (how to fix it)

code:

var_dump($each->promotion-type); 

returns:

 PHP Notice: Use of undefined constant type - assumed 'type' in newfile.php on line 19 

I canโ€™t change this variable name like how I get from my provider, any ideas how I can access this promotion type variable? (syntax wise)

+4
source share
1 answer

This slips out this notification because the expression is interpreted as the variable $each->promotion minus the type constant.

To access a property with a dash in its name, use curly braces and quotation marks:

 var_dump($each->{'promotion-type'}); 
+6
source

All Articles