douwen5681 2010-10-16 23:26
浏览 27

PHP数组解析

I am wondering if there are any classes for parsing PHP arrays in the general sense that you are looking back and forth over elements matching search patterns.

For example, lets say that If element "xyz" was found then I want to search backwards through the array until element "abc" or "cba" is found (or X number of steps backward is reached).

So I'm not sure how to describe this other than "regex for arrays". Does anyone know of any classes for this? My goal is to find data patterns in arrays that contain elements indexed in a certain order.

  • 写回答

1条回答 默认 最新

  • drs3925 2010-10-17 02:01
    关注

    The standard array functions in PHP should get you pretty close: (assuming your array is $arr)

    $key = array_search("xyz", $arr, true);
    if($key != false){
       $subset = array_slice($arr, 0, $key);
       $search2 = array_search("abc", $subset, true);
    }
    

    If you want to search backwards (formally, backwards) you can do so by reversing the array before searching it with array_reverse, and if you want to set a limit on steps backwards you can make a smaller slice.

    评论

报告相同问题?

悬赏问题

  • ¥30 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!