Learning PHP: Is there a way to make a one-line conditional statement when there more than one function calls and the break command?
-
When there is code like this, for ($i=1; $i<=5; $i++) { if ( $var ) { break; } } I know it can be shorten to this way: for ($i=1; $i<=5; $i++) { if ( $var ) break; } But if it is like this and has one function, for ($i=1; $i<=5; $i++) { if ( $var ) { need_to_do_something(); break; } } is there a way to make the if-block just one line?
-
Answer:
for ($i=1; $i<=5; $i++) { if ( $var && need_to_do_something() ) break; } && is a shortcircuit condition, means the second part won't be executed if $var is false Assuming need_to_do_something() returns something that IF considers to be true, there you go
Maxim Postoronca at Quora Visit the source
Related Q & A:
- Is there a way to make text bigger in a game room?Best solution by Yahoo! Answers
- What would be a creative way to make a timeline?Best solution by Yahoo! Answers
- Is there a way to edit a line of tracking interference down recorded video tape on computer?Best solution by Yahoo! Answers
- What's the best way to make a good impression at a job interview?Best solution by Yahoo! Answers
- Is there a way to make a collage online?Best solution by Yahoo! Answers
Just Added Q & A:
- How many active mobile subscribers are there in China?Best solution by Quora
- How to find the right vacation?Best solution by bookit.com
- How To Make Your Own Primer?Best solution by thekrazycouponlady.com
- How do you get the domain & range?Best solution by ChaCha
- How do you open pop up blockers?Best solution by Yahoo! Answers
For every problem there is a solution! Proved by Solucija.
-
Got an issue and looking for advice?
-
Ask Solucija to search every corner of the Web for help.
-
Get workable solutions and helpful tips in a moment.
Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.