The best way of creating transient values within a template is through EE's built in layout variable system.
Layout variables can be defined as single values or as part of an addressable array, and can contain anything you can generate as tag output within a template.
The only wrinkle is that the variables only get instantiated when EE template processing transfers to a subsequent template (using EE's Template Layout system). So the most minimal way of defining and then using a variable would be something like this:
First Template in chain
{layout='template_2'}
{layout:set name="my_var" value="foo"}
{layout:set name="my_var_another_option"}foo{/layout:set}
Second Template in chain ('template_2')
<h1>Here is the content of my_var {layout:my_var}</h1>
<p>And here is the content of my_var_another_option {layout:my_var_another_option}.</p>
I'll leave you to read about the layout variable array option in the docs... :)
HTH