3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php $tab1 = array(0,0,2,3,4,2,1,2,3,4,5,6,7,8,7,7,2,9,10,12,11,12,13,14,13,12,15,16,2,17,1,18,2,19,20); $tab2 = range(1,20); var_dump($tab1); var_dump($tab2); var_dump(array_search($tab2[0], $tab1)); foreach ($tab2 as $value) { var_dump(array_slice($tab1,array_search($value, $tab1))); }
based on JjnHn
Output for 5.4.0 - 7.2.0
array(35) { [0]=> int(0) [1]=> int(0) [2]=> int(2) [3]=> int(3) [4]=> int(4) [5]=> int(2) [6]=> int(1) [7]=> int(2) [8]=> int(3) [9]=> int(4) [10]=> int(5) [11]=> int(6) [12]=> int(7) [13]=> int(8) [14]=> int(7) [15]=> int(7) [16]=> int(2) [17]=> int(9) [18]=> int(10) [19]=> int(12) [20]=> int(11) [21]=> int(12) [22]=> int(13) [23]=> int(14) [24]=> int(13) [25]=> int(12) [26]=> int(15) [27]=> int(16) [28]=> int(2) [29]=> int(17) [30]=> int(1) [31]=> int(18) [32]=> int(2) [33]=> int(19) [34]=> int(20) } array(20) { [0]=> int(1) [1]=> int(2) [2]=> int(3) [3]=> int(4) [4]=> int(5) [5]=> int(6) [6]=> int(7) [7]=> int(8) [8]=> int(9) [9]=> int(10) [10]=> int(11) [11]=> int(12) [12]=> int(13) [13]=> int(14) [14]=> int(15) [15]=> int(16) [16]=> int(17) [17]=> int(18) [18]=> int(19) [19]=> int(20) } int(6) array(29) { [0]=> int(1) [1]=> int(2) [2]=> int(3) [3]=> int(4) [4]=> int(5) [5]=> int(6) [6]=> int(7) [7]=> int(8) [8]=> int(7) [9]=> int(7) [10]=> int(2) [11]=> int(9) [12]=> int(10) [13]=> int(12) [14]=> int(11) [15]=> int(12) [16]=> int(13) [17]=> int(14) [18]=> int(13) [19]=> int(12) [20]=> int(15) [21]=> int(16) [22]=> int(2) [23]=> int(17) [24]=> int(1) [25]=> int(18) [26]=> int(2) [27]=> int(19) [28]=> int(20) } array(33) { [0]=> int(2) [1]=> int(3) [2]=> int(4) [3]=> int(2) [4]=> int(1) [5]=> int(2) [6]=> int(3) [7]=> int(4) [8]=> int(5) [9]=> int(6) [10]=> int(7) [11]=> int(8) [12]=> int(7) [13]=> int(7) [14]=> int(2) [15]=> int(9) [16]=> int(10) [17]=> int(12) [18]=> int(11) [19]=> int(12) [20]=> int(13) [21]=> int(14) [22]=> int(13) [23]=> int(12) [24]=> int(15) [25]=> int(16) [26]=> int(2) [27]=> int(17) [28]=> int(1) [29]=> int(18) [30]=> int(2) [31]=> int(19) [32]=> int(20) } array(32) { [0]=> int(3) [1]=> int(4) [2]=> int(2) [3]=> int(1) [4]=> int(2) [5]=> int(3) [6]=> int(4) [7]=> int(5) [8]=> int(6) [9]=> int(7) [10]=> int(8) [11]=> int(7) [12]=> int(7) [13]=> int(2) [14]=> int(9) [15]=> int(10) [16]=> int(12) [17]=> int(11) [18]=> int(12) [19]=> int(13) [20]=> int(14) [21]=> int(13) [22]=> int(12) [23]=> int(15) [24]=> int(16) [25]=> int(2) [26]=> int(17) [27]=> int(1) [28]=> int(18) [29]=> int(2) [30]=> int(19) [31]=> int(20) } array(31) { [0]=> int(4) [1]=> int(2) [2]=> int(1) [3]=> int(2) [4]=> int(3) [5]=> int(4) [6]=> int(5) [7]=> int(6) [8]=> int(7) [9]=> int(8) [10]=> int(7) [11]=> int(7) [12]=> int(2) [13]=> int(9) [14]=> int(10) [15]=> int(12) [16]=> int(11) [17]=> int(12) [18]=> int(13) [19]=> int(14) [20]=> int(13) [21]=> int(12) [22]=> int(15) [23]=> int(16) [24]=> int(2) [25]=> int(17) [26]=> int(1) [27]=> int(18) [28]=> int(2) [29]=> int(19) [30]=> int(20) } array(25) { [0]=> int(5) [1]=> int(6) [2]=> int(7) [3]=> int(8) [4]=> int(7) [5]=> int(7) [6]=> int(2) [7]=> int(9) [8]=> int(10) [9]=> int(12) [10]=> int(11) [11]=> int(12) [12]=> int(13) [13]=> int(14) [14]=> int(13) [15]=> int(12) [16]=> int(15) [17]=> int(16) [18]=> int(2) [19]=> int(17) [20]=> int(1) [21]=> int(18) [22]=> int(2) [23]=> int(19) [24]=> int(20) } array(24) { [0]=> int(6) [1]=> int(7) [2]=> int(8) [3]=> int(7) [4]=> int(7) [5]=> int(2) [6]=> int(9) [7]=> int(10) [8]=> int(12) [9]=> int(11) [10]=> int(12) [11]=> int(13) [12]=> int(14) [13]=> int(13) [14]=> int(12) [15]=> int(15) [16]=> int(16) [17]=> int(2) [18]=> int(17) [19]=> int(1) [20]=> int(18) [21]=> int(2) [22]=> int(19) [23]=> int(20) } array(23) { [0]=> int(7) [1]=> int(8) [2]=> int(7) [3]=> int(7) [4]=> int(2) [5]=> int(9) [6]=> int(10) [7]=> int(12) [8]=> int(11) [9]=> int(12) [10]=> int(13) [11]=> int(14) [12]=> int(13) [13]=> int(12) [14]=> int(15) [15]=> int(16) [16]=> int(2) [17]=> int(17) [18]=> int(1) [19]=> int(18) [20]=> int(2) [21]=> int(19) [22]=> int(20) } array(22) { [0]=> int(8) [1]=> int(7) [2]=> int(7) [3]=> int(2) [4]=> int(9) [5]=> int(10) [6]=> int(12) [7]=> int(11) [8]=> int(12) [9]=> int(13) [10]=> int(14) [11]=> int(13) [12]=> int(12) [13]=> int(15) [14]=> int(16) [15]=> int(2) [16]=> int(17) [17]=> int(1) [18]=> int(18) [19]=> int(2) [20]=> int(19) [21]=> int(20) } array(18) { [0]=> int(9) [1]=> int(10) [2]=> int(12) [3]=> int(11) [4]=> int(12) [5]=> int(13) [6]=> int(14) [7]=> int(13) [8]=> int(12) [9]=> int(15) [10]=> int(16) [11]=> int(2) [12]=> int(17) [13]=> int(1) [14]=> int(18) [15]=> int(2) [16]=> int(19) [17]=> int(20) } array(17) { [0]=> int(10) [1]=> int(12) [2]=> int(11) [3]=> int(12) [4]=> int(13) [5]=> int(14) [6]=> int(13) [7]=> int(12) [8]=> int(15) [9]=> int(16) [10]=> int(2) [11]=> int(17) [12]=> int(1) [13]=> int(18) [14]=> int(2) [15]=> int(19) [16]=> int(20) } array(15) { [0]=> int(11) [1]=> int(12) [2]=> int(13) [3]=> int(14) [4]=> int(13) [5]=> int(12) [6]=> int(15) [7]=> int(16) [8]=> int(2) [9]=> int(17) [10]=> int(1) [11]=> int(18) [12]=> int(2) [13]=> int(19) [14]=> int(20) } array(16) { [0]=> int(12) [1]=> int(11) [2]=> int(12) [3]=> int(13) [4]=> int(14) [5]=> int(13) [6]=> int(12) [7]=> int(15) [8]=> int(16) [9]=> int(2) [10]=> int(17) [11]=> int(1) [12]=> int(18) [13]=> int(2) [14]=> int(19) [15]=> int(20) } array(13) { [0]=> int(13) [1]=> int(14) [2]=> int(13) [3]=> int(12) [4]=> int(15) [5]=> int(16) [6]=> int(2) [7]=> int(17) [8]=> int(1) [9]=> int(18) [10]=> int(2) [11]=> int(19) [12]=> int(20) } array(12) { [0]=> int(14) [1]=> int(13) [2]=> int(12) [3]=> int(15) [4]=> int(16) [5]=> int(2) [6]=> int(17) [7]=> int(1) [8]=> int(18) [9]=> int(2) [10]=> int(19) [11]=> int(20) } array(9) { [0]=> int(15) [1]=> int(16) [2]=> int(2) [3]=> int(17) [4]=> int(1) [5]=> int(18) [6]=> int(2) [7]=> int(19) [8]=> int(20) } array(8) { [0]=> int(16) [1]=> int(2) [2]=> int(17) [3]=> int(1) [4]=> int(18) [5]=> int(2) [6]=> int(19) [7]=> int(20) } array(6) { [0]=> int(17) [1]=> int(1) [2]=> int(18) [3]=> int(2) [4]=> int(19) [5]=> int(20) } array(4) { [0]=> int(18) [1]=> int(2) [2]=> int(19) [3]=> int(20) } array(2) { [0]=> int(19) [1]=> int(20) } array(1) { [0]=> int(20) }