drqxfmfa804578 2015-08-25 08:28
浏览 54
已采纳

json_encode在两个数组之间添加一行

I am working with array and json_encode, I having two array for example .

Array1:
-------
    [0] => Hotels
    [1] => Hotels-Hotels - Apartments
    [2] => Hotels - ibis
    [3] => Hotels - hotel
    [4] => Hotels - muscat
    [5] => Hotels - stay
    [6] => ---------------------------
Array2:
    [7] => First
    [8] => Second
    [9] => Third
echo json_encode($result, TRUE);exit

the result is

{"status":true,"response":["---------------------------","First","Second","Third"]}

But I need join the previous array value also, and the "----------"(line) should not be selectable.

  • 写回答

1条回答 默认 最新

  • douxian9706 2015-08-25 08:40
    关注


    Merge your array before encoding them :

    json_encode(array_merge($array_1, $array2));
    

    Do some clean up operations on your arrays:

    function array_cleanup($array) {
        // remove undesired cells...
        return $array;
    }
    

    You have an error using json_encode() function: the second parameter must be an unsigned integer and not a boolean, please read carefully the official documentation of json_encode: http://php.net/manual/en/function.json-encode.php

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
  • ¥15 想问一下树莓派接上显示屏后出现如图所示画面,是什么问题导致的
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
  • ¥500 火焰左右视图、视差(基于双目相机)
  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败