John Davidson

php - Dynamically construct object selection based on string

0 comments
Message:


Considering I have a string entity.field_one.field_two.value, how can I take this and construct a selection on an existing PHP object? Based on the string above I want to construct:


$output = $entity->field_one->field_two->value;

I'm aware that I can use variables like $entity->{$var1} but considering I don't know how many dots there are going to be, I need to find a way to construct the whole thing dynamically.


Any help appreciated!



My Answer:
>field_one->field_two->value;

Rate this post

4 of 5 based on 7913 votes

Comments




© 2024 Hayatsk.info - Personal Blogs Platform. All Rights Reserved.
Create blog  |  Privacy Policy  |  Terms & Conditions  |  Contact Us