语法'%s'和'%d'是什么意思作为调用变量的简写?

use*_*637 4 php oop

在这个例子中'%s'和'%d'是什么意思?它似乎是调用变量的简写.这种语法只能在一个类中使用吗?

// Class
class Building {
    // Object variables/properties
    private $number_of_floors = 5; // These buildings have 5 floors
    private $color;

    // Class constructor
    public function __construct($paint) {
        $this->color = $paint;
    }

    public function describe() {
        printf('This building has %d floors. It is %s in color.', 
            $this->number_of_floors, 
            $this->color
        );
    }
}
Run Code Online (Sandbox Code Playgroud)

编辑:令我困惑的部分是编译器如何知道%d指的是哪个变量?它是否按照成员变量的声明顺序排列?

bar*_*oon 11

它们是格式说明符,意味着指定类型的变量将插入到该位置的输出中.此语法也适用于类之外.

从文档:

d - 将参数视为整数,并以(带符号)十进制数表示.

s - 将参数视为字符串并显示为字符串.

请参阅printf手册.有关格式说明符的列表,请参见此处.