doudang2537 2012-01-19 02:38
浏览 25
已采纳

搜索关键字返回键的数组

I've done some searching and have found similar questions but most of them have string keys and not numerical. Basically this is what I would like to achieve:

Sample Array

 Array (
      [0] => comments=DISABLED
      [1] => img_carousel=red.jpg,yellow.png,blue.jpg
      [2] => twitter=http://www.twitter.com
 )

Running something like this:

 $img_carousel = explode('=', $arr[array_search('img_carousel', $arr)]);

will return:

 Array (
      [0] => img_carousel
      [1] => red.jpg,yellow.png,blue.jpg
 )

However, it does not and only returns 0/FALSE. I'm guessing it is because array_search searches for an exact match and not for a keyword within a string?

I tried to use preg_grep, unfortunately, I just can't seem to understand regex and searching for a literal string has proven to be too difficult for me... :{

  • 写回答

3条回答 默认 最新

  • drr25281 2012-01-19 02:50
    关注

    You want something like this:

    $img_carousel = explode('=', array_shift(preg_grep('/img_carousel=/', $arr)))
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 目前主流的音乐软件,像网易云音乐,QQ音乐他们的前端和后台部分是用的什么技术实现的?求解!
  • ¥60 pb数据库修改与连接
  • ¥15 spss统计中二分类变量和有序变量的相关性分析可以用kendall相关分析吗?
  • ¥15 拟通过pc下指令到安卓系统,如果追求响应速度,尽可能无延迟,是不是用安卓模拟器会优于实体的安卓手机?如果是,可以快多少毫秒?
  • ¥20 神经网络Sequential name=sequential, built=False
  • ¥16 Qphython 用xlrd读取excel报错
  • ¥15 单片机学习顺序问题!!
  • ¥15 ikuai客户端多拨vpn,重启总是有个别重拨不上
  • ¥20 关于#anlogic#sdram#的问题,如何解决?(关键词-performance)
  • ¥15 相敏解调 matlab