Help to multiply certain part in echo

Hello,

I have an API wherein users can request the price of the item.
When the price is echoed, the server response is as below,

PRICE:384

I want to multiply only the number part with some constant. For eg. if I want to double the price of it how would I do it?

Doing like this isn’t helping me,

case 'getPrice':
     $price = $_GET['getPrice'];
     echo $price*2;

I just get a response as 0PRICE:384 instead I want it to display PRICE:768

Thanks.

You need to split $price into two at the colon multiply the right half and then combine it back with the first half and echo it out. The explode tag is probably the best way to do this.

I tried the explode tag but it’s just prepending :0 to PRICE.
Actually I am parsing an API server response and then I need to multiply it.

You probably want something like:
$temp_price = explode(":",$price);
$price = $temp_price[0].":".($temp_price[1]*2);
echo $price;

Sponsor our Newsletter | Privacy Policy | Terms of Service