3v4l.org

run code in 500+ PHP versions simultaneously
<?php class ArraySliceIterator implements IteratorAggregate { private LimitIterator $backingIterator; public function __construct(array $array, int $offset, int $limit) { $this->backingIterator = new LimitIterator( new ArrayIterator($array), $offset, $limit ); } public function getIterator(): Traversable { return $this->backingIterator; } } function iter_search(mixed $needle, iterable $haystack, bool $strict = false): int|string|false { foreach ( $haystack as $key => $value ) { echo "$key? "; if ( ( $strict && $value === $needle ) || ( ! $strict && $value == $needle ) ) { return $key; } } echo "\nNo more items :("; return false; } $bigArray = range(0, 10_000); $key = iter_search(1066, new ArraySliceIterator($bigArray, 1_000, 100)); echo "\nResult: "; var_dump($key); echo "\n\n----\n\n"; $key = iter_search(1966, new ArraySliceIterator($bigArray, 1_000, 100)); echo "\nResult: "; var_dump($key);
Output for git.master_jit, git.master
1000? 1001? 1002? 1003? 1004? 1005? 1006? 1007? 1008? 1009? 1010? 1011? 1012? 1013? 1014? 1015? 1016? 1017? 1018? 1019? 1020? 1021? 1022? 1023? 1024? 1025? 1026? 1027? 1028? 1029? 1030? 1031? 1032? 1033? 1034? 1035? 1036? 1037? 1038? 1039? 1040? 1041? 1042? 1043? 1044? 1045? 1046? 1047? 1048? 1049? 1050? 1051? 1052? 1053? 1054? 1055? 1056? 1057? 1058? 1059? 1060? 1061? 1062? 1063? 1064? 1065? 1066? Result: int(1066) ---- 1000? 1001? 1002? 1003? 1004? 1005? 1006? 1007? 1008? 1009? 1010? 1011? 1012? 1013? 1014? 1015? 1016? 1017? 1018? 1019? 1020? 1021? 1022? 1023? 1024? 1025? 1026? 1027? 1028? 1029? 1030? 1031? 1032? 1033? 1034? 1035? 1036? 1037? 1038? 1039? 1040? 1041? 1042? 1043? 1044? 1045? 1046? 1047? 1048? 1049? 1050? 1051? 1052? 1053? 1054? 1055? 1056? 1057? 1058? 1059? 1060? 1061? 1062? 1063? 1064? 1065? 1066? 1067? 1068? 1069? 1070? 1071? 1072? 1073? 1074? 1075? 1076? 1077? 1078? 1079? 1080? 1081? 1082? 1083? 1084? 1085? 1086? 1087? 1088? 1089? 1090? 1091? 1092? 1093? 1094? 1095? 1096? 1097? 1098? 1099? No more items :( Result: bool(false)

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:
49.97 ms | 868 KiB | 4 Q