2

我有一个这样的数组

Array
(
[0] => Array
    (
        [Unit] => Array
            (
                [Unit] => ST109347005
                [SplitCnt] => 0
                [UWin] => 
                [Unit>Part] => MOLDTOOLREPAIR
                [Unit>UK1] => MOLDSHELF1
                [Unit>UK2] => 28149813MH001
                [Unit>UK3] => MOLDTOOL
            )

    )
...

并想像这样提取存储在“单元”(例如:ST109347005)中的序列数组

$newarray = Set::extract($data,'/Unit[Unit>UK1=MOLDSHELF1][Unit>UK3=MOLDTOOL]/Unit');

这不起作用,因为 > 是保留字符。我不确定允许它工作的语法是什么。我想它会是这样的(这是行不通的)

$newarray = Set::extract($data,'/Unit[Unit\>UK1=MOLDSHELF1][Unit\>UK3=MOLDTOOL]/Unit');

谢谢

4

1 回答 1

1

最后归结为Set::matches,它将Unit>UK1=MOLDSHELF1作为条件接收,并使用正则表达式对其进行评估。不支持转义字符,因此match将 视为>运算符,因此它将失败。

You'll need to rename the keys, at least temporarily for extraction, however when you're already iterating over all the entries you could easily compare the keys manually and skip the renaming and the extraction via Set::extract. Ideally you should rename the keys permanently.

于 2012-12-03T03:38:55.933 回答