Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6805509
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T19:35:43+00:00 2026-05-26T19:35:43+00:00

I’m having problems with this code below. I would like someone tell me why

  • 0

I’m having problems with this code below. I would like someone tell me why the echo $menu; is bringing the unexpected 0 (zero) as result? $t is with data, below i took a var_dump to show you…

<div class="cont_menu">
  <div class="menu">
    <ul>
      <?php
      include_once 'banco_pdo.php';

      $sql = 'SELECT colaborador_menu_cod,colaborador_menu_sup_cod,menu_descr,menu_nivel,menu_titulo,menu_url   FROM colaborador_menu WHERE colaborador_menu_cod in (SELECT colaborador_menu_cod as id FROM menu_por_colaborador WHERE col_cod = :col_cod)';
      $colaborador = $_SESSION["colaborador"];
      try {
          $core = Core::getInstance();
          $stmt = $core->dbh->prepare($sql);
          $stmt->bindParam('col_cod',$colaborador, PDO::PARAM_INT);
          $stmt->execute();
          $t = $stmt->fetchALL(PDO::FETCH_ASSOC);
      } catch (PDOException $e) {
          echo $e->getMessage();
      }
      unset($sql);unset($core);unset($stmt);unset($colaborador);

      if(!empty($t))
      {
          foreach($t as $linha)
          {
              if($linha['menu_nivel'] == 1)
              { $principal[] = $linha; }
              else
              { $subcat[] = $linha; }
          }
          $menu = '';

          foreach($principal as $linha2)
          {
              $menu = $menu + "<li><a class=\"hide\" title=\"".$linha2["menu_titulo"]."\" href=\"#\" style=\"font-weight:bold;\">".$linha2["menu_descr"]."</a><!--[if lte IE 6]><a href=\"#\">".$linha2["menu_descr"]."<table><tr><td><![endif]--><ul>";
              foreach($subcat as $linha3)
              { 
                  if($linha3["colaborador_menu_sup_cod"] == $linha2["colaborador_menu_cod"])
                  {
                      $menu = $menu + "<li><a href=\"".$linha3["menu_url"]."\" title=\"".$linha3["menu_titulo"]."\">".$linha3["menu_descr"]."</a></li>";
                  }
          }
          $menu = $menu + '</ul><!--[if lte IE 6]></td></tr></table></a><![endif]--></li>';
      }
      echo $menu;
  }
  ?>
  </ul>
</div>

This is the var_dump of the $t variable:

array
  0 => 
    array
      'colaborador_menu_cod' => string '1' (length=1)
      'colaborador_menu_sup_cod' => null
      'menu_descr' => string 'CATALOGO' (length=8)
      'menu_nivel' => string '1' (length=1)
      'menu_titulo' => string '#' (length=1)
      'menu_url' => string 'CATALOGO' (length=8)
  1 => 
    array
      'colaborador_menu_cod' => string '2' (length=1)
      'colaborador_menu_sup_cod' => string '1' (length=1)
      'menu_descr' => string 'CATEG. E PROD.' (length=14)
      'menu_nivel' => string '2' (length=1)
      'menu_titulo' => string 'Categoria e Produtos' (length=20)
      'menu_url' => string 'udi_categoria.php?listar=cat_nivel&par=1&op=insert&nivel=1' (length=58)
  2 => 
    array
      'colaborador_menu_cod' => string '3' (length=1)
      'colaborador_menu_sup_cod' => string '1' (length=1)
      'menu_descr' => string 'PROD. S/ CAT.' (length=13)
      'menu_nivel' => string '2' (length=1)
      'menu_titulo' => string 'Produtos sem Categoria' (length=22)
      'menu_url' => string 'prod_sem_cat.php' (length=16)
  3 => 
    array
      'colaborador_menu_cod' => string '4' (length=1)
      'colaborador_menu_sup_cod' => string '1' (length=1)
      'menu_descr' => string 'CARACTERISTICA' (length=14)
      'menu_nivel' => string '2' (length=1)
      'menu_titulo' => string 'Caracteristica de Produtos' (length=26)
      'menu_url' => string 'udi_caracteristica.php?op=insert' (length=32)
  4 => 
    array
      'colaborador_menu_cod' => string '5' (length=1)
      'colaborador_menu_sup_cod' => string '1' (length=1)
      'menu_descr' => string 'MENU' (length=4)
      'menu_nivel' => string '2' (length=1)
      'menu_titulo' => string 'Menus' (length=5)
      'menu_url' => string 'udi_menu.php?listar=menu_nivel&par=1&op=insert&menu_nivel=1' (length=59)
  5 => 
    array
      'colaborador_menu_cod' => string '6' (length=1)
      'colaborador_menu_sup_cod' => string '1' (length=1)
      'menu_descr' => string 'USUARIOS' (length=8)
      'menu_nivel' => string '2' (length=1)
      'menu_titulo' => string 'usuarios' (length=8)
      'menu_url' => string 'udi_usuario.php?op=insert' (length=25)
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T19:35:44+00:00Added an answer on May 26, 2026 at 7:35 pm

    PHP uses the . operator for string concatenation, not +. You have some code like this:

    $menu = $menu + "...some text...";
    

    Use this instead:

    $menu = $menu . "...some text...";
    

    Or even:

    $menu .= "...some text...";
    

    + tries to add two numbers. If either of the strings cannot be converted to numbers, zero is assumed. The sum of zero and zero is zero, so $menu is zero if you use +.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I would like to count the length of a string with PHP. The string
For some reason, after submitting a string like this Jack’s Spindle from a text
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
Does anyone know how can I replace this 2 symbol below from the string
I have this code to decode numeric html entities to the UTF8 equivalent character.
I would like to run a str_replace or preg_replace which looks for certain words
this is what i have right now Drawing an RSS feed into the php,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.