「PHP」 json_encodeで 値を JSON 形式にして返す

説明
json_encode(mixed $value, int $flags = 0, int $depth = 512): string|false
与えられた value を JSON 形式にした文字列を返します。

使用例

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<!DOCTYPE html>
<html>
<body>
<?php
$age = array("User01"=>35, "TestUser"=>37, "Joe"=>43);
echo json_encode($age);
?>
</body>
</html>
<!DOCTYPE html> <html> <body> <?php $age = array("User01"=>35, "TestUser"=>37, "Joe"=>43); echo json_encode($age); ?> </body> </html>
<!DOCTYPE html>
<html>
<body>

<?php
$age = array("User01"=>35, "TestUser"=>37, "Joe"=>43);

echo json_encode($age);
?>

</body>
</html>

結果
{“User01″:35,"TestUser":37,"Joe":43}

PHP

Posted by arkgame