From a big picture point of view I would say the main problem is that you are not looking at the error messages. And I suspect that you are trying to trouble shoot the problem inside of a much bigger chunk of code by refreshing your browser.
Start by turning on error reporting:
<?php
# keys.php
error_reporting(E_ALL);
And then test your code from a console window with something like
> php keys.php
At that point, it will become immediately obvious that:
$string = ('1234' => 'example');
Has invalid syntax. I think you intended it to be an array though $string is somewhat of an unusual name for an array. It is also possible that you think json_encode takes a string as input. Which would explain the second error:
$keys = json_encode($string,true);
The docs clearly show that the first argument should be a php array and the second optional argument needs to be an integer.
Get past those first two errors and then see what happens.
And as a final note, consider using some sort of php aware IDE for your editor. Both of the above mentioned errors would have been flagged long before you tried executing the code.
I’m not sure what the point of json encoding an array is if you’re just going to decode it again in the same script and reference it like an array. Just use the array in the first place (once it actually is a syntactically-correct array, anyway).
I agree, I use visual studio right now, and while I do get some PHP error notices, I don’t get the tools a dedicated IDE for PHP would have. I am certainly going to look into that.
I check my errors, which I 100% should have done earlier, and found that this was an issue with MySQL, and not this code.