配列の構造化マークアップ

例えば、以下のように株価の配列を書き出す。

<?php

$array = array(
  "code" => "4779",
  "name" => "ラクオリア創薬",
  "price" => "1728"
);
?>
<script type="application/ld+json">
{
	"code" : "<?php echo $array&#91;code&#93;; ?>",
	"name" : "<?php echo $array&#91;name&#93;; ?>",
	"price" : "<?php echo $array&#91;price&#93;; ?>",
}
</script>

jsonにencodeすれば、吐き出す必要はなし。

<?php
$array = array(
  "code" => "4779",
  "name" => "ラクオリア創薬",
  "price" => "1728"
);
$json = json_encode($array, JSON_UNESCAPED_UNICODE);
?>

<script type="application/ld+json">
<?php print $json; ?>
</script>