You would probably be better off doing this outside of the table and then adding in the final result to the table. There are a variety of ways to do what you want, depending on where the data is coming from and how it's being stored in the hash table.

To give you the best code possible, you'd need to give more details about what's being done here.

Example details you could provide (you can provide others):

* Does the table item always have the same fruits (or whatever)? For example, will it always have apples and grapes and so on? This is helpful because it's easier to write a short regex if you know the item will be listed.

* Are the items always the same ones (no one can add something new)? For example, it doesn't take random words from people. This is useful because you could very easily make the fruit/etc order be the same all of the time and then just use $gettok() with $calc() or similar.

* Does the table need everything listed in one item, or can they have their own items? This is useful because if each fruit/etc can have its own item in the table, then it's extremely easy to update the numbers.

* Any other info would help. Where are you getting the input from (users, generated from script, etc)? What's the purpose of the script? Etc. We could give you something that would work without knowing the information, but it would be almost guaranteed to be inefficient for what you actually need.


EDIT: hixxy beat my post and did give you a working method. I still think that you can get a better method if you provide the additional details.

Last edited by Riamus2; 23/05/11 06:41 PM.