tags:

views:

74

answers:

4

Is there a way I can perform one PHP function first and then execute another function after the first function?

+2  A: 
func1();
func2();
deceze
A: 

You could always nest the function calls, so that the last step in function 1 is executing function 2. This is assuming, of course, that the execution of Function 2 ALWAYS follows Function 1.

That is, function1() { // do stuff; function2(); }

Andrew
Why that?... it is the same as executing them separately one after another... as `function(); someOtherFunction();`
Garis Suero
Good question. It's simply a matter of, if this is always the case, it saves writing by 50%.
Andrew
+4  A: 

PHP executes code sequentially. If you have two function calls:

foo();
bar();
// more code

it will execute the lines in foo sequentially, return to the line after that call (bar();), and execute it, which will call bar and execute its lines sequentially. Then bar will return to the line after the bar(); call (// more code) and execution will continue there

Michael Mrozek
+2  A: 
if (function1()) (
    function2();
)

?

Andrew Heath