1

How can i increment x or y in this JSON file? I posted my PHP code to increment the counter, but i dont know how to acces the "infos" -> "x" or "y".

JSON file

{
  "counter": 4,
  "infos": {
    "x": 1,
    "y": 2
  }
}

PHP file

<?php
$contents = file_get_contents('../test.json');
$contentsDecoded = json_decode($contents, true);

$contentsDecoded['counter']++;

$json = json_encode($contentsDecoded);
file_put_contents('../test.json', $json);
?>
2
  • 3
    $contentsDecoded['infos']['x']++? Commented Mar 26, 2018 at 22:30
  • sometimes its sooo easy.... it works THANK YOU <3 Commented Mar 26, 2018 at 22:32

1 Answer 1

1

Just use

$decoded['infos']['x']++;
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.