Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I am working with a database created by a university professor's intern. Many of the fields have names like 'Revenues_(budget)'.

Currently when working with objects that have the fields as properties I do something like

$f = 'Revenues_(budget)';
echo $obj->$f;

This works fine but I was wondering if there might be a more elegant or at least concise way to handle these?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
320 views
Welcome To Ask or Share your Answers For Others

1 Answer

You can do that in one expression:

echo $obj->{'Revenues_(budget)'};

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...