Another little note. Always try to give meaningful names to your variables. It is much better when other developers can read your code without help of comments or trying to dig into the code.

Like in this example it is tempting to use $i but almost in any language with foreach loop we can now give meaningful variable names instead of $i for index. Maybe $name or $session_varaible_name would be better.