PHP Object to Array help
Go to solution
Solved by Aho,
First of all, $OBJECT is a JSON array, but it is invalid JSON. The JSON spec doesn't allow single quotes so json_decode will likely fail.
To begin, fix $OBJECT:
$OBJECT = '[{"type":"IRON_BOOTS","damage":153},{"type":"IRON_LEGGINGS","damage":153},{"type":"IRON_CHESTPLATE","damage":153},{"type":"IRON_HELMET","damage":153}]';
Decode it to a PHP object:
$foo = json_decode($OBJECT);
Access the values:
for ($i = 0; $i < count($foo); $i++){ echo $foo[$i]->type; echo $foo[$i]->damage;}
Output (no line breaks):
IRON_BOOTS153IRON_LEGGINGS153IRON_CHESTPLATE153IRON_HELMET153
Unless I made a few typos, this will work fine.
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now