dqb78642 2016-04-15 12:49
浏览 62
已采纳

如何在php中将数组转换为JSON对象[重复]

This question already has an answer here:

I want to convert my array value:

Array ( [page_1] => fifth [page_2] => first [page_3] => fourth [page_4] => third ) 

Into JSON format is given below

{s:6:"page_1";s:5:"third";s:6:"page_2";s:5:"first";s:6:"page_3";s:6:"fourth";s:6:"page_4";s:5:"fifth";}

Can anyone please help me

</div>
  • 写回答

3条回答 默认 最新

  • dqpfkzu360216 2016-04-15 12:54
    关注

    You want to serialize you array.

    You need to use serialize()

    <?php
    $a = array (
            'page_1' => 'fifth',
            'page_2' => 'first',
            'page_3' => 'fourth',
            'page_4' => 'third');
    echo serialize($a);
    // Outputs: a:4:{s:6:"page_1";s:5:"fifth";s:6:"page_2";s:5:"first";s:6:"page_3";s:6:"fourth";s:6:"page_4";s:5:"third";}
    ?>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 Markdown在VScode编辑器下插入视频
  • ¥15 stm32c8t6工程,使用hal库
  • ¥100 有偿求易语言word文档取doc和docx页数方法或模块
  • ¥15 找能接spark如图片的,可议价
  • ¥15 关于#单片机#的问题,请各位专家解答!
  • ¥15 博通raid 的写入速度很高也很低
  • ¥15 目标计数模型训练过程中的问题
  • ¥100 Acess连接SQL 数据库后 不能用中文筛选
  • ¥15 用友U9Cloud的webapi
  • ¥20 电脑拓展屏桌面被莫名遮挡