How to create array of object from values of another variable in php? -


working code:

$node1 = new stdclass(); $node1->field_granule_comments1['und'][0]['value'] = "test"; print_r($node1);  

result

stdclass object (     [field_x] => array         (             [und] => array                 (                     [0] => array                         (                             [value] => test                         )                 )          )  ) 

i need output have value in variable. example:

$id="field_x['und'][0]['value']"; $node2 = new stdclass(); $node2->$id ="test"; print_r($node2); 

output of code :

stdclass object (     [field_x['und'][0]['value']] => test ) 

how can come output similar "working result", taking value variable ?

try this:

$id="field_x['und'][0]['value']"; $node2 = new stdclass(); $node2->{$id} ="test"; print_r($node2); 

enclose $id variable variable within curly brackets.


Comments

Popular posts from this blog

python - Subclassed QStyledItemDelegate ignores Stylesheet -

java - HttpClient 3.1 Connection pooling vs HttpClient 4.3.2 -

SQL: Divide the sum of values in one table with the count of rows in another -