Twój kod niestety nie odwzorowuje problemu. Chodzi o to, że $i jest traktowane jako dana z formularza a jednocześnie i cała nazwa musi być przekazana do funkcji jako string, z której trzeba zrobić array, żeby wydobyć $i.
Poniższa funkcja działa perfect gdy name jest jednowymiarowy, ale gdy name ma wiele wymiarów sypie się. Gdy do Generatora dochodzi nazwa pola name (np. "data[1]"), pole wygeneruje się dobrze (z name="data[1]"), ale gdy przychodzi do sprawdzania tabeli POST to sprawdza $_POST['data[1]'] i tu się zacina.
private function GenerateTextField ($strType, $arrFuncArgs) {
$strName = $arrFuncArgs[1];
$strValueFromBase = $arrFuncArgs[2];
$strValueDefault = $arrFuncArgs[3];
$strAddArguments = (isSet($arrFuncArgs[4
])) ?
$arrFuncArgs[4
] : null;
if (isSet($_POST[$strName])) { $strValue = $_POST[$strName];
} else if (!isSet($_POST[$strName]) AND
!empty($strValueFromBase)) { $strValue = $strValueFromBase;
} else if (empty($strValueFromBase)) { $strValue = $strValueDefault;
}
$strReturn = '<input type="' . $strType . '" name="' . $strName . '" value="' . $strValue . '" ' . $strAddArguments . '/>';
return $strReturn;
}
Ideę ewentualnego rozwiązania przedstawiam poniżej, tylko może można to zrobić bardziej profesjonalnie niż takie stringowanie
<?php
$a['cos1']['15'] = "test";
$f = "cos1[15]";
foreach ($g as $key1 => $value1) {
if (substr($value1, -1) == "]") { }
}
}
echo '<pre>a ' . print_r($a[$g[0
]][$g[1]],1 ) . '</pre>'; ?>