-1

I have this php script:

<?php $categories = $this->requestAction('categories/topmenu');
    function RecursiveCategories($array)
    {
        if (count($array))
        {
            foreach ($array as $category)
            {
                if (count($category['children']))
                {
                    echo '<li >';
                    echo '<a href="/v-n/'.$category['Category']['id'].'-'.$category['Category']['slug'].'" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">';
                    echo '<div class="sub-menu">'.$category['Category']['name'].'</div>';
                    echo '</a>';
                    echo '<div class="tn-gnavsub">'; 
                    echo '<div class="gnavsub">'; 
                    echo '<ul class="menufix">'; 
                    RecursiveCategories($category['children']);
                    echo '</ul>';
                    echo '</div>';
                    echo '</div>';
                    echo '</li>'; 
                }
                else
                {
                    echo '<li><a href="/v-n/'.$category['Category']['id'].'-'.$category['Category']['slug'].'"> '.$category['Category']['name'].'</a></li>';
                }
            }
        }

    }
?>
<?php RecursiveCategories($categories); ?>

I get this error:

Fatal error: Cannot redeclare RecursiveCategories() (previously declared in :36) in... on line 64

slavoo
  • 5,798
  • 64
  • 37
  • 39

1 Answers1

0

You have included the same function definition via Include statement or some other file, so that's why you got this problem. use the following :

   if (!function_exists('RecursiveCategories')) {
       function RecursiveCategories($array)
       {
        //code goes here
       }
   }
   

Recommended: add all functions inside a lib file and use include_once command to include the lib.php file.

Senthil
  • 2,156
  • 1
  • 14
  • 19