例えば、以下のように株価の配列を書き出す。
<?php $array = array( "code" => "4779", "name" => "ラクオリア創薬", "price" => "1728" ); ?> <script type="application/ld+json"> { "code" : "<?php echo $array[code]; ?>", "name" : "<?php echo $array[name]; ?>", "price" : "<?php echo $array[price]; ?>", } </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>