3v4l.org

run code in 300+ PHP versions simultaneously
<?php function checkCase($string) { // --- 列出标点的转换规则 $symMap = [ "." => ">", "," => "<" ]; foreach($symMap as $k => $v) $symMap[$v] = $k; // 列出标点的转换规则 --- // --- 列出各种可能情况 // $element = [["a", "A"], [".", ">"], ["b", "B"]] $element = str_split($string); foreach($element as &$item) { if(in_array($item, $symMap)) $item = [$item, $symMap[$item]]; else $item = [strtolower($item), strtoupper($item)]; } // 列出各种可能情况 --- // 记录当前的组合状态,每一项对应 $element 中的每一项 $flags = array_fill(0, count($element), 0); // 记录结果 $result = []; while(true) { $solution = ""; // 组合当前一条结果 foreach(range(0, count($element) - 1) as $i) $solution .= $element[$i][$flags[$i]]; // 改变当前状态,同时返回是否已经到达了末尾 $isEnding = function() use(&$flags, $element) { foreach(range(0, count($flags) - 1) as $i) { if($flags[$i] < count($element[$i]) - 1) { $flags[$i]++; if($i > 0) foreach(range(0, $i - 1) as $j) $flags[$j] = 0; return false; } } return true; }; if(!$isEnding()) $result[] = $solution; else break; } return $result; } var_dump(checkCase("A.B")); var_dump(checkCase("ABCD"));
Output for git.master, git.master_jit, rfc.property-hooks
array(7) { [0]=> string(3) "a.b" [1]=> string(3) "A.b" [2]=> string(3) "a>b" [3]=> string(3) "A>b" [4]=> string(3) "a.B" [5]=> string(3) "A.B" [6]=> string(3) "a>B" } array(15) { [0]=> string(4) "abcd" [1]=> string(4) "Abcd" [2]=> string(4) "aBcd" [3]=> string(4) "ABcd" [4]=> string(4) "abCd" [5]=> string(4) "AbCd" [6]=> string(4) "aBCd" [7]=> string(4) "ABCd" [8]=> string(4) "abcD" [9]=> string(4) "AbcD" [10]=> string(4) "aBcD" [11]=> string(4) "ABcD" [12]=> string(4) "abCD" [13]=> string(4) "AbCD" [14]=> string(4) "aBCD" }

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:
39.58 ms | 402 KiB | 8 Q