Jump to content

Php incrementing /w decimal places.


whelpton

Recommended Posts

<?php

function version_add($current,$add){
$current = explode('.',$current);
$add = explode('.',$add);
foreach($current as $key=>$value){
	$current[$key] += $add[$key];
}
return implode('.',$current);
}

$currentversion = '0.2.1'; 
$newversion = version_add($currentversion,'0.0.1');

echo $newversion;

EDIT: PFMaBiSmAd beat me to it  :P

 

$currentversion = '0.2.1';

$v = explode('.', $currentversion);
if($v[2] < 9)
$v[2]++;
elseif($v[1] < 9) {
$v[1]++;
$v[2] = 0;
} elseif($v[0] < 9) {
$v[0]++;
$v[1] = 0;
if($v[1] == 0)
   $v[2] = 0;
}

$newversion = implode('.',$v);

echo $newversion;

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.