Get Array data and display, this code functions good, but why, and is it proper?

I wrote this code to use when ‘getting’ database data that was saved in wp custom wp options. I really don’t understand what the code is doing completely so if you can explain it please. And also tell me if it’s even proper code or if I should use different code. The reason I first started using the code is when I tried to get the data from the database data is in an Array and trying to display the data with just the first $ name gives a php/array error, so for example echo $ name gives error; so if I use the code and display for example echo $ thename, this functions good without error. I also use the normal get option code to get the data like this: $ name = get_option(‘custom_name’); … the main question is about the code below:

if (!empty($  name)) :  foreach($  name as $  thename)  {   $  name = $  thename;  } endif; 

I don’t know why it works or if it’s proper to use for getting data with get_option.

Please write me any comments or improvements so I learn and my code is more proper.