First of all, your array declaration is incorrect and you will get a syntax error if you run the code. You should use array(...) not array{...}. And the values need to be comma-separated. For example:
array(
key => value,
key2 => value2,
key3 => value3,
...
)
The following should work:
$runners = array(
'fname' => 5,
'you' => 6
);
echo json_encode($runners);
Output:
{"fname":5,"you":6}
How are these two different
The end result is different for both cases. When you do json_encode(array("runners"=>$runners));, the array is multi-dimensional, and the JSON output will change, too:
{"runners":{"fname":5,"you":6}}
Which one should you use
Depends. In the first array, you are simply creating two keys named fname and you, and in the second, you also add another key, runners, thereby making the array multi-dimensional. If you want that information to be present in the resulting JSON string, you should use the second one. If not, use the first one.