Quinn Humphreys Quinn Humphreys - 3 years ago 160
PHP Question

PHP how to increment

I would like to increment this number

$numero1 = "1.0.1"
. So what I did is
$numerosumado = $numero1 + 1
but it's not working because of the dots. So my question is how do I do it?

Answer Source

Note: This is just one way out of many...

<?php
$numero1 = "1.9.1";
$numerosumado = explode( ".", $numero1 );
if ( ++$numerosumado[2] > 9 ) {
    $numerosumado[2] = 0;
    if ( ++$numerosumado[1] > 9 ) {
        $numerosumado[1] = 0;
        ++$numerosumado[0];
    }
}
$numerosumado = implode( ".", $numerosumado );
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download