开发者

CSV parse + multidim arrays

59516,?O?L?h,27,80,67,13,1,84.6,40,4,1,32632,??,3,5,32640,AES,3,5,32210,\
???i?Z??,1,1.2,32263,?,1,1.2,3?T,1,1.2,32104,,1,1,40012,??,1,0.8

How would I explode/list this line and pull any field that contains a five-character number and the field immediately preceding it?

i.e. $data['59516']['i'] would contain an array with

(32632=>1, 32640=>5, 3开发者_Go百科2210=>5, 32263=>1.2,32104=>2, 40012=>1)


Not sure i fully understand your question, but it sounds like you want something like:

$items = str_getcsv($commaSeparatedList);
for ($i = 0; $i < count($items); $i++) {
    if (strlen($items[$i]) == 5 && is_numeric($items[$i])) {
            var_dump($items[$i]); // current match
        if (isset($items[$i-1])) {
            var_dump($items[$i-1]); // item and one before it
        }
    }
 }


(?<=,)(\d+),(\d{5})

The $matches[1] has the value and the $matches[2] has your key.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜