dongxu7408 2013-05-22 11:18
浏览 16
已采纳

需要帮助转换布尔值

this is actually WordPress but I think it is more of PHP question.

I am using SMOF framework (it is for theme option setting) and flexslider. TO combine bothe of them, in one of flexslider option, I have to use whether "true" or "false". The thing is, SMOF returns "0" and "1" instead of "true" or "false" - the word. So I need to convert "0" to "false" and "1" to "true"

I have this code:

function isBoolean($slider_loop) {
    $slider_loop = $smof_data['slider_loop'];
   if ($slider_loop === "true") {
      return true;
   } else {
      return false;
   }
   return $slider_loop;
}

..., and then in flexslider's "side":

animationLoop: "<?php echo isBoolean($slider_loop); ?>"

but it is not working.

Ideally, it should be something like this:

animationLoop: "<?php echo $smof_data['slider_loop'] 
// this return "0" and "1", while it should be "true" or "false" for flexslider to work ?>"

So, how should I do it?

Thanks in advance.

  • 写回答

4条回答 默认 最新

  • dongpan3001 2013-05-22 11:32
    关注

    How about you take advantage of dynamic typing and type casting ? It's as simple as:

    return (bool)$smof_data['slider_loop'];
    

    ..

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥15 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
  • ¥15 关于#hadoop#的问题