php - 如何将“px”附加到数组值?
问题描述
我正在开发一个 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
存在,则使用此值 AND append px
。否则值应该是fit-content
。
我试着这样写,但它不起作用:
$bar_height = $options['wprcb_api_number_field_barHeight'] ? ($options['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';
它应该可以正常工作
推荐阅读
- cube.js - cube.js:将原始 sql 查询发送到多维数据集服务器
- c++ - 如果我们已经在 .h 文件中添加了相同的命名空间,我们是否需要为 -inl.h 添加相同的命名空间
- javascript - 我无法在 VSCode 中运行控制台登录
- asp.net-core - 两个客户端之间的 asp.NET 核心 signalR 隧道
- c++ - 如何通过引用函数传递对象并访问公共结构中的变量
- wordpress - 在 wordpress 上构建祈祷词的表格
- c# - 按住两个按钮时,Sprite 只会向一个方向移动
- java - 在android应用程序中使用viewpager 2覆盖在底部导航和抽屉布局中的片段
- bluetooth - 为 Cycling Trainer 解码蓝牙 HCI 日志
- android - arrayListOf 显示 Int 而不是 String - Kotlin