Hi there, I have a code, which checks for some value in an array foreach ($array as $val) if(isset($e->$val)) echo $e->$val; PHP: How to put the results of this construction to a variable? For example: $а=$e->$val; - returns only the last result of the loop.
If you only want the last value, just set the variable on each pass. In the end you will be left with the last variable. foreach ($array as $val): if(isset($e->$val)): $а=$e->$val; echo $e->$val; endif; endforeach; PHP:
sorry for misunderstanding, it returns several values and I need each of them in a variable. They'll go to a db after all.
Like this? $return = array(); foreach ($array as $val) if(isset($e->$val)) $return[] = $e->$val; PHP: And then you can run another foreach to do whatever you need to do with the data.
Thanks a lot, it works for me. Here is another question. How to get a part of string from start to some mark (for example a tag), then from another mark (end of the tag) to the end?
would you guys help me with the reg_exp? {Text A}<some_tag>Blah-blah</some_tag>{Text B}<some_tag>Blah-blah</some_tag>{Text C} HTML: I need {Text A},{Text B},{Text C}. And mind, that tags can be without closing tag. Thanks.