php array() w/ foreach only loops if using .= to build the result -
php array() w/ foreach only loops if using .= to build the result -
i have frustrating problem cannot result. not adding up.
i passing array process on foreach() so:
if (is_array($seminar)) { foreach ($seminar $sem_id) $sem_id_list .= "$sem_id"; echo "$sem_id<br />"; }
as can see array() $seminar, , output looks so:
array ( [0] => 3 [1] => 8 [2] => 9 [3] => 13 [4] => 14 [5] => 15 )
as can see in code, building block w/ =. like: *$sem_id_list .= "$sem_id";* , when echoed out looks like: 389131415 expected.
but when trying iterate through , print each value like: *echo "$sem_id";* lastly array() item!!
i've never run problem before. guessing missing dead simple here, experience should working , printing results fine.
as side note, var_dump($seminar); produces too:
array(6) { [0]=> string(1) "3" [1]=> string(1) "8" [2]=> string(1) "9" [3]=> string(2) "13" [4]=> string(2) "14" [5]=> string(2) "15" }
you're missing opening brace of foreach
, closing brace. try:
if (is_array($seminar)) { foreach ($seminar $sem_id) { $sem_id_list .= "$sem_id"; echo "$sem_id<br />"; } }
or build list , print @ end:
if (is_array($seminar)) { foreach ($seminar $sem_id) { $sem_id_list .= "$sem_id"; } echo "$sem_id_list"; }
php arrays loops foreach
Comments
Post a Comment