How to get value of an associative HTML array in PHP using a string?

前端 未结 3 1618
礼貌的吻别
礼貌的吻别 2021-01-29 08:19

Look I have a form like this:

I want t

3条回答
  •  -上瘾入骨i
    2021-01-29 08:59

    You can use preg_match_all() to get all the indexes in the string into an array:

    $indexes = preg_match_all('/(?<=\[\')(?:[^\']*)(?=\'\])/', $str);
    $indexes = $indexes[0]; // Get just the whole matches
    

    Then use a loop to drill into $_POST.

    $cur = $_POST;
    foreach ($indexes as $index) {
        $cur = $cur[$index];
    }
    

    At this point $cur will contain the value you want.

提交回复
热议问题