3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php $wbs = '.002.001.005'; function getParentActionID($wbs){ $pieces = explode(".", $wbs); $resultat = array(); for($i = 1; $i < count($pieces)-1; $i++){ $invID = str_pad($pieces[$i], 3, '0', STR_PAD_LEFT); $newstr = substr_replace($invID, ".", 0, 0); array_push($resultat, $newstr); } $newRes = implode("", $resultat); return $newRes; } echo "Parent ID : "; var_dump(getParentActionID($wbs)); echo "</br>"; function getPreviousSiblingID($wbs){ $pieces = explode(".", $wbs); $resultat = array(); $invID = end($pieces) - 1; $wbsPrevious = substr_replace(str_pad($invID, 3, '0', STR_PAD_LEFT), ".", 0, 0); for($i = 1; $i < count($pieces)-1; $i++){ $invID = str_pad($pieces[$i], 3, '0', STR_PAD_LEFT); $newstr = substr_replace($invID, ".", 0, 0); array_push($resultat, $newstr); } array_push($resultat, $wbsPrevious); $newRes = implode("", $resultat); return $newRes; } echo "Previous Sibling ID : "; var_dump(getPreviousSiblingID($wbs)); echo "</br>";
Output for 4.3.0 - 5.6.21, hhvm-3.10.0 - 3.12.0, 7.0.0 - 7.1.0
Parent ID : string(8) ".002.001" </br>Previous Sibling ID : string(12) ".002.001.004" </br>