Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP correct indentation?

I'm a beginner PHP coder, recently I've been told I indent my code not correctly. They say this is wrong:

    if($something) {
        do_something();
        }
    else {
        something_more();
        and_more();
        }

While this is right?

    if($something) {
        do_something();
    } else {
        something_more();
        and_more();
    }

Really? I am willing to become opensource coder in nearest future so that's why I'm asking how to write code in a good way.

like image 291
user321311 Avatar asked Apr 20 '10 13:04

user321311


1 Answers

Both ways will run just fine. Whichever is more comfortable for you and your team would be the way to go. I personally favor the second example, or something alone these lines:

if ($something)
{
  do_something();
}
else
{
  do_something_else();
  pet_the_ponies();
}

There's no real right answer to this.

like image 80
Sampson Avatar answered Oct 07 '22 13:10

Sampson