dongtu1357
2012-06-05 09:46
浏览 30
已采纳

如果版本大于1.5.1.3,则进行Opencart测试

How would I add an IF statement to check if the opencart version is greater than 1.5.1.3?

This is defined in the index.php as:

// Version
define('VERSION', '1.5.0');

I have tried: if((int)VERSION >= '1.5.1.3'){ although when I convert this into an int it becomes empty.

Also I tried this with the same effect:

$this->data['oc_version'] = (int)str_replace('.', '', VERSION);
if($this->data['oc_version'] >= 1513){

Do I need to convert this into an int to correctly perform greater/less than calculations?

图片转代码服务由CSDN问答提供 功能建议

如何添加IF语句以检查opencart版本是否大于1.5.1.3?

这在index.php中定义为:

  // Version 
define('VERSION','1.5.0'); 
    
 
 

我试过: if((int)VERSION> ='1.5.1.3'){虽然我把它转换为int 它变得空虚。

我也尝试了同样的效果:

  $ this-> data ['oc_version'] =(int)str_replace  ('。','',VERSION); 
if($ this-> data ['oc_version']> = 1513){
   
 
 

我是否 需要将其转换为int以正确执行大于/小于计算?

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

2条回答 默认 最新

  • dongshai2022 2012-06-05 13:15
    已采纳
    if(version_compare(VERSION, '1.5.1.3', '>')) {
        // CODE HERE IF HIGHER
    } else {
        // CODE HERE IF LOWER
    }
    

    Though the 1.5.1.3 branch actually goes up to 1.5.1.3.1 so I'm guessing you want it to be that

    点赞 打赏 评论
  • duanchi6397 2014-05-29 23:16

    I tried this recently and couldnt get it working as above, perhaps its a PHP version thing but I got it working with:

    if(version_compare(VERSION, '1.5.1.3') > 0) {
        // CODE HERE IF HIGHER
    } else {
        // CODE HERE IF LOWER
    }
    

    Hope that helps someone else. Got the code from here: http://us2.php.net/manual/en/function.version-compare.php

    点赞 打赏 评论

相关推荐 更多相似问题