title: Adding up integers php
body: <p>I am attempting to add up all the string lengths of each menu item I have so I can have a character limit for my entire navigation rather than a set limit on each item. </p>
  
  <p>I am currently using the Walker_Nav_Menu in WordPress. I can get each individual length but I can't add them all together in one variable. </p>
  
  <p>First I check to see if the item is a main header not a sub menu and then use strlen to get the length of the text.</p>
  
  <pre><code>class top_bar_walker extends Walker_Nav_Menu {
      function start_el(&amp;$output, $item, $depth, $args) {
          global $wp_query;
  
  
              if( $item-&gt;menu_item_parent == 0 ) {
              $length = strlen( $item-&gt;title );
  
              }
  
  
              var_dump($length);
  
  
  
  
          $indent = ($depth) ? str_repeat("\t", $depth) : '';
  
          $class_names = $value = '';
  
          $classes = empty($item-&gt;classes) ? array() : (array) $item-&gt;classes;
  
          $classes[] = ($item-&gt;current) ? 'active' : '';
          $classes[] = ($args-&gt;has_children) ? 'has-dropdown' : '';
  
          $args-&gt;link_before = (in_array('section', $classes)) ? '&lt;label&gt;' : '';
          $args-&gt;link_after = (in_array('section', $classes)) ? '&lt;/label&gt;' : '';
          $output .= (in_array('section', $classes)) ? '&lt;li class="divider"&gt;&lt;/li&gt;' : '';
  
          $class_names = join(' ', apply_filters('nav_menu_css_class', array_filter($classes), $item, $args ) );
          $class_names = strlen(trim($class_names)) &gt; 0 ? ' class="'.esc_attr($class_names).'"' : '';
  
          $output .= ($depth == 0) ? $indent.'&lt;li class="divider"&gt;&lt;/li&gt;' : '';
          $output .= $indent.'&lt;li id="menu-item-'.$item-&gt;ID.'"'.$value.$class_names.'&gt;';
  
          $attributes  = !empty($item-&gt;attr_title) ? ' title="' .esc_attr($item-&gt;attr_title).'"' : '';
          $attributes .= !empty($item-&gt;target)     ? ' target="'.esc_attr($item-&gt;target    ).'"' : '';
          $attributes .= !empty($item-&gt;xfn)        ? ' rel="'   .esc_attr($item-&gt;xfn       ).'"' : '';
          $attributes .= !empty($item-&gt;url)        ? ' href="'  .esc_attr($item-&gt;url       ).'"' : '';
  
  
          $item_output  = $args-&gt;before;
          $item_output .= (!in_array('section', $classes)) ? '&lt;a'.$attributes.'&gt;' : '';
          // Find out if menu item is top level. If character size is greater than 15, cut down string and add '..''
          $item_output .= $args-&gt;link_before.($item-&gt;menu_item_parent == 0 &amp;&amp; strlen( $item-&gt;title ) &gt; 10 ) ?  trim( substr( apply_filters( 'the_title', $item-&gt;title, $item-&gt;ID ), 0, 10 ) ).".." : apply_filters('the_title', $item-&gt;title, $item-&gt;ID);
          $item_output .= $args-&gt;link_after;
          $item_output .= (!in_array('section', $classes)) ? '&lt;/a&gt;' : '';
          $item_output .= $args-&gt;after;
  
  
  
          $output .= apply_filters('walker_nav_menu_start_el', $item_output, $item, $depth, $args);
      }
  </code></pre>
  
  <p>When I do a var dump of $length I get </p>
  
  <pre><code>int(38) NULL NULL int(32) NULL int(16) NULL int(18) NULL int(42) NULL int(20) NULL 
  </code></pre>
  
  <p>But i am unable to add them together</p>
  
  <p>Any help would be appreciated.</p>