Skip to content
Advertisement

Array Data Unable to be Iterated Through (PHP)

NOTE: This is just test code because I am learning PHP, so there’s no real point to it.

Essentially, all I’m asking is how to turn the array of objects back into a form that I can use.

ISSUE: I’ve created a new object array with 8 different produce items. I would like to write them to a .txt file and then re-access the array objects data after they have been encoded. Currently, I am getting an error of “Trying to get property ‘price’ of non-object,” and I’m not sure why.

JavaScript

This is what ProducePrice.txt looks like:

[ {"name":"bananas","price":0.59},{"name":"grapes","price":2.99},{"name":"apples","price":1.49},{"name":"pears","price":1.39},{"name":"lettuce","price":0.99},{"name":"onions","price":0.79},{"name":"potatoes","price":0.59},{"name":"peaches","price":1.59} ]

Advertisement

Answer

Nvm, figured it out.

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