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.

    评论

报告相同问题?

悬赏问题

  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 关于大棚监测的pcb板设计
  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器
  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
  • ¥15 Vue3地图和异步函数使用
  • ¥15 C++ yoloV5改写遇到的问题