三元运算符问题

I'l*_*ack 6 php

我原以为输出会是:

http://domain.dev/category/123

但实际输出是: ""

$condition = true;
$categoryId = 123;
$result = 'http://domain.dev/category' . empty($condition) ? '' : '/' . $categoryId;

var_dump($result);
Run Code Online (Sandbox Code Playgroud)

从我的理解-它是否empty($condition)是空的-如果为true,则追加http://domain.dev/category''要不然/$categoryId

我做错了什么?

小智 9

只是()陈述声明:

$result = 'http://domain.dev/category' . (empty($condition) ? '' : '/' . $categoryId);
Run Code Online (Sandbox Code Playgroud)

所以它被视为运营商