douzhanglun4482 2017-07-22 13:57
浏览 52
已采纳

为什么array_flip不能在我的PHP脚本中工作?

I am trying to reverse the keys and values of this string but it seems not to be working. What might be the issue?

$input = '"85"=>"1","86"=>"2","87"=>"3","88"=>"4","89"=>"5","90"=>"6","91"=>"7","92"=>"8","93"=>"9","94"=>"10","95"=>"11","96"=>"12","97"=>"13","98"=>"14","99"=>"15","100"=>"16","101"=>"17","102"=>"18","103"=>"19","104"=>"20","105"=>"21","106"=>"22","107"=>"23","108"=>"24","109"=>"25","110"=>"26","111"=>"27","112"=>"28","113"=>"29","114"=>"30","115"=>"31","116"=>"32","117"=>"33","118"=>"34","119"=>"35","120"=>"36","121"=>"37","122"=>"38","123"=>"39","124"=>"40","125"=>"41","126"=>"42","127"=>"43","128"=>"44","129"=>"45","130"=>"46","131"=>"47","132"=>"48","133"=>"49","134"=>"50","135"=>"51","136"=>"52","137"=>"53","138"=>"54","139"=>"55","140"=>"56","141"=>"57","142"=>"58","143"=>"59","144"=>"60","145"=>"61","146"=>"62","147"=>"63","148"=>"64","149"=>"65","150"=>"66","151"=>"67","152"=>"68","153"=>"69","154"=>"70","155"=>"71","156"=>"72","157"=>"73","158"=>"74","159"=>"75","160"=>"76","161"=>"77","162"=>"78","163"=>"79","164"=>"80","165"=>"81","166"=>"82","167"=>"83","168"=>"84","169"=>"85","170"=>"86","171"=>"87","172"=>"88","173"=>"89","174"=>"90","175"=>"91","176"=>"92","177"=>"93","178"=>"94","179"=>"95","180"=>"96","181"=>"97","182"=>"98","183"=>"99","184"=>"100","185"=>"101","186"=>"102","187"=>"103","188"=>"104","189"=>"105","190"=>"106","191"=>"107","192"=>"108","193"=>"109","194"=>"110","195"=>"111","196"=>"112","197"=>"113","198"=>"114","199"=>"115","200"=>"116","201"=>"117","202"=>"118","203"=>"119","204"=>"120","205"=>"121","206"=>"122","207"=>"123","208"=>"124","209"=>"125","210"=>"126"';
$result = array($input);
$result=array_flip($result);
print_r($result);
  • 写回答

3条回答 默认 最新

  • dousong5161 2017-07-22 14:01
    关注

    array($input) does not return what you think it does. array does not parse your string. So you'll have to do that first. If your input string does not use => anywhere else than where it divides a key and value, then you could do a replacement to make it JSON, and then decode it:

    $result = json_decode("{" . str_replace("=>", ":", $input) . "}", true);
    $result = array_flip($result);
    print_r($result);
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 seatunnel-web使用SQL组件时候后台报错,无法找到表格
  • ¥15 fpga自动售货机数码管(相关搜索:数字时钟)
  • ¥15 用前端向数据库插入数据,通过debug发现数据能走到后端,但是放行之后就会提示错误
  • ¥30 3天&7天&&15天&销量如何统计同一行
  • ¥30 帮我写一段可以读取LD2450数据并计算距离的Arduino代码
  • ¥15 飞机曲面部件如机翼,壁板等具体的孔位模型
  • ¥15 vs2019中数据导出问题
  • ¥20 云服务Linux系统TCP-MSS值修改?
  • ¥20 关于#单片机#的问题:项目:使用模拟iic与ov2640通讯环境:F407问题:读取的ID号总是0xff,自己调了调发现在读从机数据时,SDA线上并未有信号变化(语言-c语言)
  • ¥20 怎么在stm32门禁成品上增加查询记录功能