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 单片机学习顺序问题!!
  • ¥15 ikuai客户端多拨vpn,重启总是有个别重拨不上
  • ¥20 关于#anlogic#sdram#的问题,如何解决?(关键词-performance)
  • ¥15 相敏解调 matlab
  • ¥15 求lingo代码和思路
  • ¥15 公交车和无人机协同运输
  • ¥15 stm32代码移植没反应
  • ¥15 matlab基于pde算法图像修复,为什么只能对示例图像有效
  • ¥100 连续两帧图像高速减法
  • ¥15 如何绘制动力学系统的相图