I have wrote this code:
$final = array(
($data[0] - $data[1]),
($data[1] - $data[2]),
($data[2] - $data[3]),
($data[3] - $data[4]),
($data[4] - $data[5]),
($data[5] - $data[6])
);
Some of them will return negative numbers (-13,-42 etc…), how to change the negative ones to 0?
By the way the think i do after is:
$data_string = join(",", $final);
Example: I need to convert it like in the following:
1,3,-14,53,23,-15 => 1,3,0,53,23,0
I like Hakre’s compact answer. However, if you have a more complex requirement, you can use a function:
http://codepad.org/viGBYj4f (With an
echoto show the$resultbefore test.)Which gives you:
Note, you could also just return the ternary:
As well as using it in a loop:
http://codepad.org/31WCbpNr