Why do PHP variables need to be pre-defined before a loop in order to use it inside of (and subsequently outside of) the loop?
foreach( $formats as $format => $src ){
if ( !empty( $src ) ) {
$source .= '<source type="' . $format . '" src="' . $src . '">';
}
}
echo $source;
Shows "undefined variable" $source
foreach( $formats as $format => $src ){
$source2 = '';
if ( !empty( $src ) ) {
$source2 .= '<source type="' . $format . '" src="' . $src . '">';
}
}
echo $source2;
Returns only the last item in the variable but there is no undefined variable
Seems weird to me that it almost acts like a variable scope issue.