I keep getting
Warning: Illegal string offset 'type' in ... on line ...
I've tried following the answers here Illegal string offset Warning PHP
by doing something like
if(isset($_POST['type_'.$i]))
$$T['type'] = $_POST['type_'.$i];
but it still gives errors, I think it might have something to do with variable variables (it's the first time I am using them. Below is my code:
for($i = 1; $i <= 15; $i++){
$T = 'T'.$i;
$$T['type'] = $_POST['type_'.$i];
$$T['hidden'] = $_POST['hidden_'.$i];
$$T['require'] = $_POST['require_'.$i];
if(isset($_POST['question_'.$i.'_list']))
$$T['list'] = $_POST['quesiton_'.$i.'_list'];
}
I won't like to create arrays T1, T2 ... T15, with the following values ['type'], ['hidden'], ['require'], ['list'].
$$T = array();before trying to assign any values to it.Tvariables to be arrays? What if you set them to be before setting the values inside them?$$T = array();$$T = array();didn't work$Tis not an array and you are trying to access it like it is or you need to wrap$T['type']in curly braces because the$$Tassignment is happening before the array lookup. Try${$T['type']}. Curly braces in assignment are like parenthesis in expressions.$$Tis likely doing a string conversion of the array$Tmaking a variable called$Arrayand then looking up a key of['type']on the string.