3v4l.org

run code in 300+ PHP versions simultaneously
<?php $desc = "GLOVE EXAM BEST TCH ALOE LTX MED 100/BX 10BX/CS"; $uom = "BX"; $keywords = explode(" ", $desc); // print_r($keywords); $pkgstring = ""; $result = []; foreach ($keywords as $key => $keyword){ $firstchar = substr($keyword, 0, 1); if (is_numeric($firstchar)) { $pkgstring .= $keyword.","; } } $pkgstring = substr($pkgstring, 0, -1); $result['pkgstring'] = $pkgstring; $str_ele = explode(",", $pkgstring); $qty_uom = 1; $new_arr[0] = ""; $pos = 1; if (stripos($pkgstring, $uom) !== false){ // sort each element in the best order to execute the rest of the function foreach ($str_ele as $key => $element) { if (stripos($element, '/') !== false) { $x = stripos($element, '/'); $chk = substr($element, $x-1, 1); if (is_numeric($chk)) { $new_arr[0] = $element; } else { $new_arr[$pos] = $element; $pos++; } } } // do the math to get the qty/uom foreach ($new_arr as $key => $str) { echo $str."\n\n"; if (stripos($str, '/'.$uom) !== false) { $size = preg_replace('/[^0-9]/', '', $str); $qty_uom *= $size; break; } else { $size = preg_replace('/[^0-9]/', '', $str); $qty_uom *= $size; } } } $result['qty_uom'] = $qty_uom; print_r($result);
Output for git.master_jit, git.master, rfc.property-hooks
100/BX Array ( [pkgstring] => 100/BX,10BX/CS [qty_uom] => 100 )

This tab shows result from various feature-branches currently under review by the php developers. Contact me to have additional branches featured.

Active branches

Archived branches

Once feature-branches are merged or declined, they are no longer available. Their functionality (when merged) can be viewed from the main output page


preferences:
63.31 ms | 401 KiB | 8 Q