【发布时间】:2012-01-13 11:46:39
【问题描述】:
我有一个输入:
<input name="subscription[login]" />
我正在创建一个函数,该函数采用数组(例如 $_POST)和 html 名称(subscription[login])。
它应该返回给我$_POST['subscripton']['login']的引用
所以我做了:
public static function &getSubArrayRefFromPath($arr, $arrPath) {
if(!is_array($arrPath)) {
throw new Exception('$arrPath is not an array');
}
else {
$el = $arr;
foreach($arrPath as $k) {
$el &= $el[$k];
}
return $el;
}
}
public static function &getSubArrayRefFromHtmlPath($arr, $htmlPath) {
$regex = '#^([a-z]+)(?:\[([a-z]+)\]){2}(\[\])?$#i';
preg_match($regex, $htmlPath, $rawKeys);
}
但我无法使用正则表达式检索所有值:
我在 rawKeys 中得到了这个:
array
0 => string 'abc[def][ghi]' (length=13)
1 => string 'abc' (length=3)
2 => string 'ghi' (length=3)
我可能错过了什么..
【问题讨论】: