3v4l.org

run code in 300+ PHP versions simultaneously
<?php function mkProductList($array) { // $tmpVal get product of all elements $tmpVal = 1; // Count zeros in array $cnt = count(array_keys($array, 0)); // If there are two or more zeros, then product of all elements will be zero // No make sense to do // Fill array with zeros and return it if ($cnt > 1) { $array = array_fill_keys(array_keys($array), 0); return $array; } // If there are one or no zeros, then get product of all elements, exclude zero, // cause multiply by zero equal zero foreach($array as $value) { if ($value != 0) { $tmpVal *= $value; } } // If there are one zero, then product of all elements will be zero // exclude zero position in input array, it will be product of all elements if ($cnt == 1) { $array = array_fill_keys(array_keys($array), 0); $array[array_search(0, $array)] = $tmpVal; return $array; } // If there are no zeros, then we replace velues in input array // Product of all elements we devide by current element value // Result is product of all elements, exclude current element value foreach($array as $key => $value) { $array[$key] = $tmpVal / $value; } return $array; } // tests var_dump(producePatStr(array(1,2,3,4))); var_dump(producePatStr(array())); var_dump(producePatStr(array(-0.5, 100, 20))); ?>
Output for git.master, git.master_jit, rfc.property-hooks
Fatal error: Uncaught Error: Call to undefined function producePatStr() in /in/QKK25:46 Stack trace: #0 {main} thrown in /in/QKK25 on line 46
Process exited with code 255.

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:
46.54 ms | 401 KiB | 8 Q