I am dynamically creating variable to check the check boxes using loop. Actually the I am creating variable using string that is combination of 1 & 0. viz..1010101000110. Its like this. My string length is 50.
$user_authorisation = fetch_table_user($uid, '1', '12');
for ($j = 0; $j <= 49; $j++) {
if (substr($user_authorisation, $j, 1) == '1') {
$user_authorisation_field_ . $j = 'checked="checked"';
}
}
My error is:
Warning: substr() expects parameter 2 to be long, string given in C:\xampp\htdocs\shadaab\user_auth.php on line 38
They’re right, the best solution is to simply use an array:
But, specifically your problem lies in how you concatinate your variable:
$user_authorisation_field_ . $j@Dong shows how to do it correctly in his answer.
The reason the concatination is incorrect is because you want to treat
"user_authorisation_field_"as a string and combine it with a number, but you are unintentially using it as a variable$user_authorisation_field_which isUNDEFINED. So what you’re doing is basically evaluates as:etc. Doesn’t work.