3v4l.org

run code in 500+ PHP versions simultaneously
<?php $json_string = <<<EOT {"name":"KillerBot 6000","desc":"A room with very harsh moderation. Proceed with caution!","max":600,"color":"#e0e0e0","whispersenabled":true,"forbiddenCommands":["/milk", "/bal"],"msg":[{"cont":"hey, hxor?","time":1,"color":"black","type":"message","visibility":"HxOr1337","from":"UnknownUser1"},{"cont":"Welcome to the chat!","time":0,"type":"message","color":"black","visibility":"HxOr1337","from":"Test"}]} EOT; $_SESSION["ts_user"] = 'HxOr1337'; //if(isset($_GET["room"]) && file_exists("data/".$_GET["room"].".json")){ // $jsonF = file_get_contents("data/".$_GET["room"].".json"); $jsonD = json_decode($json_string, true); var_dump($jsonD); //echo count($jsonD["msg"]); // echo $jsonD["msg"][1]["type"]; foreach($jsonD["msg"] as $key => $message){ if($jsonD["msg"][$key]["visibility"] !== "all"){ if(isset($_SESSION["ts_user"]) && $_SESSION["ts_user"] == $jsonD["msg"][$key]["visibility"] && $jsonD["msg"][$key]["type"] != "rawbr"){ echo $jsonD["msg"][$key]["from"].": ".htmlspecialchars($jsonD["msg"][$key]["cont"])." [To you]", PHP_EOL; } else if($jsonD["msg"][$key]["type"] === "message"){ echo $jsonD["msg"][$key]["from"].": ".htmlspecialchars($jsonD["msg"][$key]["cont"])." [normal message]", PHP_EOL; } else if($jsonD["msg"][$key]["type"] === "rawbr"){ echo $jsonD["msg"][$key]["cont"]."<br />"; } } } //}
Output for 7.4.0 - 7.4.33, 8.0.1 - 8.0.30, 8.1.0 - 8.1.34, 8.2.0 - 8.2.30, 8.3.0 - 8.3.30, 8.4.1 - 8.4.18, 8.5.0 - 8.5.3
array(7) { ["name"]=> string(14) "KillerBot 6000" ["desc"]=> string(56) "A room with very harsh moderation. Proceed with caution!" ["max"]=> int(600) ["color"]=> string(7) "#e0e0e0" ["whispersenabled"]=> bool(true) ["forbiddenCommands"]=> array(2) { [0]=> string(5) "/milk" [1]=> string(4) "/bal" } ["msg"]=> array(2) { [0]=> array(6) { ["cont"]=> string(10) "hey, hxor?" ["time"]=> int(1) ["color"]=> string(5) "black" ["type"]=> string(7) "message" ["visibility"]=> string(8) "HxOr1337" ["from"]=> string(12) "UnknownUser1" } [1]=> array(6) { ["cont"]=> string(20) "Welcome to the chat!" ["time"]=> int(0) ["type"]=> string(7) "message" ["color"]=> string(5) "black" ["visibility"]=> string(8) "HxOr1337" ["from"]=> string(4) "Test" } } } UnknownUser1: hey, hxor? [To you] Test: Welcome to the chat! [To you]

preferences:
105.53 ms | 1458 KiB | 4 Q