I have the following code
$patron = '/{usuario}/photos/{photo_id}/comments/{comment_id}';
$array_patron = str_split($patron);
$array3 = array();
$variable_open = false;
$ind = -1;
foreach($array_patron as $i => $val){
if($val === '{'){
$variable_open = true;
$ind++;
continue;
}else if($val === '}'){
$variable_open = false;
continue;
}else if($variable_open){
$array3[$ind] .= $val; // Line number 22
}
}
print_r($array3);
I do not understand why it results in NOTICE s
NOTICE Undefined offset: 0 on line number 22
NOTICE Undefined offset: 1 on line number 22
NOTICE Undefined offset: 2 on line number 22
Even though it shows me these NOTICE s, the resulting Array () is CORRECT .
Array (
[0] => usuario
[1] => photo_id
[2] => comment_id
)
Can anyone please explain to me what happens?