rgadellaa’s avatarrgadellaa’s Twitter Archive—№ 6,356

        1. PHP bug* of the day: json_encode() sorts objects when keys are numeric. * or is this "works as intended"? 👇
      1. …in reply to @RGadellaa
        $o = []; $o["5"] = "first"; $o["2"] = "second"; json_encode($o); { "2": "second", "5": "first" }
    1. …in reply to @RGadellaa
      Notice the curly braces: { ... }, so it outputs a JSON object. But it also performed a ksort().
  1. …in reply to @RGadellaa
    Oh, if you var_dunp($o) before the json_encode, it does output the proper order. Took me a while to debug this, then I realized it changed as soon as I called json_encode().