如何将“ px”附加到数组值?

时间:2020-06-24 11:16:44

标签: php

我正在开发wordpress插件,并且在使用一些基本的php时遇到了一些困难。

<div style="display: flex; align-items:center; justify-content:center; background:{$background_color}; height:{$bar_height}; {$show_hide_border}">

如您所见,这里有height:{$bar_height}

这是对数组的调用:

$bar_height = $options['wprcb_api_number_field_barHeight'] ? $options['wprcb_api_number_field_barHeight'] : 'fit-content';

我希望它以这种方式工作: 如果wprcb_api_number_field_barHeight存在,则使用此值并附加px。 否则,该值应为fit-content

我试图用这种方式编写它,但是它不起作用:

$bar_height = $options['wprcb_api_number_field_barHeight'] ? ($options['wprcb_api_number_field_barHeight'] + 'px') : 'fit-content';

请建议如何正确编写它。

1 个答案:

答案 0 :(得分:1)

这样写:

  $bar_height = $options['wprcb_api_number_field_barHeight'] ? $options['wprcb_api_number_field_barHeight'] . 'px' : 'fit-content';

应该可以正常工作

相关问题