PHP正确的缩进? [英] PHP correct indentation?

查看:128
本文介绍了PHP正确的缩进?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是PHP初学者,最近有人告诉我我的代码缩进不正确. 他们说这是错误的:

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();
        }

这是对的吗?

    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.

推荐答案

两种方法都可以正常运行.无论哪种方式对您和您的团队来说都是更舒适的方式.我个人喜欢第二个示例,或者仅以下几行:

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();
}

对此没有真正的正确答案.

这篇关于PHP正确的缩进?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆