Skip to content
Advertisement

PHP wrong foreach code

What I have done wrong, foreach code written below, but it seems not working:

JavaScript

What I have to change in this foreach code? Thanks

Advertisement

Answer

first line, custom is not a variable (could be copy and paste error)

JavaScript

Then you are splitting a string using can array operator, you need to split that string first using:

JavaScript

Then, you have declared $custom as $each_item, but you then appear to be trying to access a sub array that doesn’t exist. $each_item[id] and $each_item[quantity] are not defined anywhere. I am guessing that you are trying to split the 8-1 into id-quantity, in which case you need to actually define those to be able to use them.

JavaScript

So your final code needs to be:

JavaScript
User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement