Communities for your favorite technologies. Explore all Collectives
Stack Overflow for Teams is now called Stack Internal. Bring the best of human thought and AI automation together at your work.
Bring the best of human thought and AI automation together at your work. Learn more
Find centralized, trusted content and collaborate around the technologies you use most.
Stack Internal
Knowledge at work
Bring the best of human thought and AI automation together at your work.
I need something like this.
var thing_<?php echo $php_var->n ?> = <?php echo '32' ?>
want to create something like this :
var thing_342 = '32'
thing['342']
You need an object, and use it as an associative array/hash/whatever you are used to call it.
var thing = {}; thing[342] = '32';
or
var thing = {342: '32'};
Add a comment
Suppose $php_var->n = 342
$php_var->n = 342
var data = <?php echo $php_var->n ?>; eval("var thing_" + data + "=32;"); alert(thing_342); // output 32
Simple example:
var data = 342; eval("var thing_" + data + "=32;"); alert(thing_342); // output 32
var container; var var_name='lolo'; container[var_name]='he he he'; alert(container.lolo);
not exactly what you want, but I guess it is close enough.
Required, but never shown
By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.
Start asking to get answers
Find the answer to your question by asking.
Explore related questions
See similar questions with these tags.
thing['342']would usually be saner.