0

Can we use two different variables in one foreach loop?

For eg: foreach ($_SESSION["stuff"], $_SESSION["diff_stuff"]) as $new_stuff {} Is there any way we can achieve this?

13th Jul 2016, 10:43 AM
Aditya Bhaskar Sharma
Aditya Bhaskar Sharma - avatar
1 Réponse
+ 1
If these two variables have same array structures, you can merge them, save it in new variable, then use it in foreach. For example : $stuff = array_merge( $_SESSION['stuff'], $_SESSION['diff_stuff'] ); foreach ( $stuff as $new_stuff ) { // do something }
31st Jul 2016, 1:23 PM
Ayub Narwidian Adiputra
Ayub Narwidian Adiputra - avatar