how can i get all of my erroes then echo them
<p>I write a php code and save all of my errors to a variable named $errors</p>

<p>First i collect my errors then print them but after that i add some errors to my errors array</p>

<p>now i cant print them , what sholud i do if i want to collect all of them then printing them?</p>

<p>here is a example code :</p>

<pre><code>$errors = array ();
//do some functions that add errors into my error array
print_r($errors);
//now do some other functions that add error to my array
//but now i cant print them .
</code></pre>

<p>i cant do any thing before printing . i want a way that $errors collect all of my errors</p>

<p>this is my code :</p>

<pre><code>&lt;?php require_once("includes/session.php"); ?&gt;
   &lt;?php require_once("includes/connection.php"); ?&gt;
   &lt;?php require_once("includes/functions.php"); ?&gt;
   &lt;?php require_once("includes/user_functions.php"); ?&gt;
   &lt;?php require_once("includes/errors_constants.php"); ?&gt;



   &lt;?php
   //create ERRORS array
    $errors;
   //get ERRORS VALUES FROM SESSION AND REMOVE DUPLICATES

   $errors = $_SESSION['errors'];
   if ($errors){
  $errors = array_unique($errors);
   }


   $action = $_GET['action'];
   $page = $_GET['page'];

   //action selection
   switch ($action){
    case "create":
    if(isset($_POST['submit'])){    
    $user_created = create_user($_POST['username'],$_POST['password'],$_POST['email']);
    }
    break;

    case "edit":
    if(isset($_POST['submit'])){
        if($_SESSION['edited_user']  == $_GET['id'])
        {
            $user_edited =      edit_user($_GET['id'],$_POST['new_password'],$_POST['email']);
        }else{
            $errors[]="UPDATE_PROBLEM";
        }
    }
    break;


    case "delete":
    if(isset($_POST['submit'])){
    $user_deleted = delete_user($_POST['user_id']);
    }
    break;
   }

   ?&gt;

   &lt;?php

   // sections of the page
  //top 
   require_once("includes/sections/top.php"); 

    //between head and body
    require_once("includes/form_js.php");

     //action selection
    switch ($action){
    case "create":
    require_once("javascripts/create_user_js.php");

    case "edit":
    require_once("javascripts/create_user_js.php");
    }


    //undertop
   require_once("includes/sections/under_top.php"); 
    //right
   require_once("includes/sections/right.php"); 
   //middle
    ?&gt;
    &lt;!-- middle section --&gt;
            &lt;div class="middle"&gt;    
            &lt;!-- make center thing in section middle --&gt;
                &lt;center&gt;
                &lt;!-- check is there any error for dispalying error box --&gt;
                &lt;?php if (!empty($errors)){?&gt;
                &lt;div class="fberrorbox"&gt;
                &lt;?php
                        foreach ($errors as $item){
                            if (@constant($item)!= null){
                            print_error(@constant($item));
                            }else {
                            print_error(DEFAULT_ERROR);
                            }
                        }
                ?&gt;
                &lt;/div&gt;
                &lt;?php   
                unset($errors);
                unset($_SESSION['errors']);
                } ?&gt;


                &lt;!-- display result --&gt;
                &lt;?php
                    if ($user_created)display_result(USER_CREATED);
                    if ($user_deleted)display_result(USER_DELETED);
                    if ($user_edited)display_result(USER_EDITED);
                ?&gt;

                 &lt;?php
                    //action selection
                    switch ($action){
                        case "create":
                        require_once("includes/user/create.php"); 
                        break;

                        case "delete":
                        require_once("includes/user/delete.php"); 
                        break;

                        case "view":
                        require_once("includes/user/list_view.php"); 
                        break;

                        case "edit":
                        require_once("includes/user/edit.php"); 
                        break;

                        default:
                        require_once("includes/user      /list_view.php"); 
                        break;  
                        }
                ?&gt;

                &lt;/center&gt;
            &lt;/div&gt;
            &lt;!-- end middle section --&gt;

   &lt;?php
   //left
   require_once("includes/sections/left.php"); 
   //bottom
   require_once("includes/sections/bottom.php"); 
    ?&gt;
</code></pre>
