douchun6108 2017-03-11 10:01
浏览 28
已采纳

如何从php数组获取这个javascript数组?

I have a javascript array

<script>
var image = document.getElementById('example-basic');

var options = {};
var data = [
  Taggd.Tag.createFromObject({
    position: { x: 0.19, y: 0.4 },
    text: 'This is a tree',
  }),
  Taggd.Tag.createFromObject({
    position: { x: 0.5, y: 0.3 },
    text: 'Pretty sure this is also a tree',
  }),
  Taggd.Tag.createFromObject({
    position: { x: 0.775, y: 0.5 },
    text: 'Can you guess this one?',
  }),
];

var taggd = new Taggd(image, options, data);
</script>

I need to create a PHP array and covert it into this javascript array can you please help me?

  • 写回答

3条回答 默认 最新

  • dongtun1872 2017-03-11 10:10
    关注

    I am not an expert in PHP, but I am sure you could output an html from php:

    <script type='text/javascript'>
     var js_ar = <?php echo json_encode($array); ?>
    </script>
    

    js_ar will be a global variable when javascript is executed on browser and can be easily accessed. I would leave variable naming up to you.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 目标检测算法移植到arm开发板
  • ¥15 利用JD51设计温度报警系统
  • ¥15 快手联盟怎么快速的跑出建立模型
  • ¥15 关于腾讯云服务器中,PHP页面无法打开的问题
  • ¥60 如何把照片修复成原始拍摄图
  • ¥80 Exited too quickly (process log may have details)
  • ¥15 爬知乎登录之后内容加载不出来
  • ¥15 怎么用protues测量通频带
  • ¥15 zepelin使用sparkInterpreter 异常
  • ¥15 paho mqtt 接收不到消息