<slide title="Array Traversal">

<blurb>
This looks a little nasty, but it isn't that bad. We make two passes of the array. First to figure out how many bytes to allocate for the result string and the second to actually build the string with a "+" between each symbol name.
</blurb>

<example type="c"><![CDATA[ else {
   /* First loop through and figure out how much memory to allocate */
   zend_hash_internal_pointer_reset_ex(target_hash, &pos);
   while(zend_hash_get_current_data_ex(target_hash,(void **)&entry, &pos)==SUCCESS) {
     convert_to_string_ex(entry);
     len += (*entry)->value.str.len;
     if(count>0) len++;  /* for the + sign */
     count++;
     zend_hash_move_forward_ex(target_hash, &pos);
   }

   str = (char *) emalloc(len + 1);

   zend_hash_internal_pointer_reset_ex(target_hash, &pos);
   while(zend_hash_get_current_data_ex(target_hash,(void **)&entry, &pos)==SUCCESS) {
     count--;
     memcpy(str + target, (*entry)->value.str.val, (*entry)->value.str.len);
     target += (*entry)->value.str.len;
     if (count > 0) {
       *(str+target) = '+';
       target++;
     }
     zend_hash_move_forward_ex(target_hash, &pos);
   }
   *(str+target) = '\0';  /* don't forget to null-terminate */
}]]></example>

</slide>
