How to display function value?

I am using this function and declare display_error(),
but error display on my screen
“Warning: Invalid argument supplied for foreach()”
help with us.

function display_error($nerrors = '')
        {
            if(isset($nerrors))
            {
            foreach($nerrors as $err)
            {
                echo $err->errors['existing_user_login'][0];

            }       

            }
        }

Related posts

Leave a Reply

1 comment

  1. Your default parameter to the function is a string and not an array. Change that to an empty array:

    function display_error($nerrors = array()) {
        foreach($nerrors as $err) {
            echo $err->errors['existing_user_login'][0];
        }
    }
    

    You can leave out the if, the loop won’t run if the array is empty.