11--TEST--
2- array_str_contains() basic and edge cases tests
2+ array_str_contains() basic functionality and edge cases
33--FILE--
44<?php
55
6- echo "--- Basic Search --- \n" ;
7- $ fruits = ['apple ' , 'banana ' , 'cherry ' , 'pineapple ' , 'grape ' ];
8- var_dump (array_str_contains ($ fruits , 'apple ' ));
6+ $ fruits = ["apple " , "banana " , "cherry " , "date " , "elderberry " ];
97
10- echo "\n--- Preserving String and Numeric Keys --- \n" ;
11- $ data = [
12- 'first ' => 'hello world ' ,
13- 10 => 'foo bar ' ,
14- 'third ' => 'world domination ' ,
15- 20 => 'just php ' ,
16- ];
17- var_dump (array_str_contains ($ data , 'world ' ));
8+ echo "--- Basic Search --- \n" ;
9+ var_dump (array_str_contains ($ fruits , "an " ));
10+ var_dump (array_str_contains ($ fruits , "berry " ));
11+ var_dump (array_str_contains ($ fruits , "xyz " ));
1812
19- echo "\n--- Non-string Values Ignored --- \n" ;
20- $ mixed = [
21- 'a ' => 'test 1 ' ,
22- 'b ' => 123 ,
23- 'c ' => null ,
24- 'd ' => 'another test ' ,
25- 'e ' => ['nested ' ],
26- 'f ' => true ,
27- ];
28- var_dump (array_str_contains ($ mixed , 'test ' ));
13+ echo "\n--- Key Preservation --- \n" ;
14+ $ assoc = ["a " => "first item " , "b " => "second item " , "c " => "third " ];
15+ var_dump (array_str_contains ($ assoc , "item " ));
2916
30- echo "\n--- Empty Needle (Matches All String Elements) --- \n" ;
31- $ items = [' one ' , 2 , ' three ' , false , '' ];
32- var_dump (array_str_contains ($ items , '' ));
17+ echo "\n--- Empty Needle --- \n" ;
18+ $ emptyNeedleTest = [" foo " , " bar " , " baz " ];
19+ var_dump (array_str_contains ($ emptyNeedleTest , "" ));
3320
3421echo "\n--- UTF-8 and Multi-byte Support --- \n" ;
35- $ persian = [
36- ' سلام دنیا ' ,
37- ' خداحافظ دنیا ' ,
38- ' تست پیاچپی ' ,
39- ' PHP 8.7 عالیه 🚀 ' ,
40- ' یک ایموجی دیگر 🚀 '
22+ $ multibyte = [
23+ " سلام دنیا " ,
24+ " خداحافظ دنیا " ,
25+ " PHP 8.7 " ,
26+ " PHP 8.7 café 🚀 " ,
27+ " یک ایموجی دیگر 🚀 " ,
4128];
42- var_dump (array_str_contains ($ persian , ' دنیا ' ));
43- var_dump (array_str_contains ($ persian , ' 🚀 ' ));
29+ var_dump (array_str_contains ($ multibyte , " دنیا " ));
30+ var_dump (array_str_contains ($ multibyte , " 🚀 " ));
4431
4532echo "\n--- Empty Haystack --- \n" ;
46- var_dump (array_str_contains ([], ' anything ' ));
33+ var_dump (array_str_contains ([], " needle " ));
4734
4835?>
4936--EXPECT--
5037--- Basic Search ---
5138array(2) {
52- [0 ]=>
53- string(5 ) "apple "
54- [3 ]=>
55- string(9 ) "pineapple "
39+ [1 ]=>
40+ string(6 ) "banana "
41+ [4 ]=>
42+ string(10 ) "elderberry "
5643}
57-
58- --- Preserving String and Numeric Keys ---
59- array(2) {
60- ["first"]=>
61- string(11) "hello world"
62- ["third"]=>
63- string(16) "world domination"
44+ array(1) {
45+ [4]=>
46+ string(10) "elderberry"
47+ }
48+ array(0) {
6449}
6550
66- --- Non-string Values Ignored ---
51+ --- Key Preservation ---
6752array(2) {
6853 ["a"]=>
69- string(6 ) "test 1 "
70- ["d "]=>
71- string(12 ) "another test "
54+ string(10 ) "first item "
55+ ["b "]=>
56+ string(11 ) "second item "
7257}
7358
74- --- Empty Needle (Matches All String Elements) ---
59+ --- Empty Needle ---
7560array(3) {
7661 [0]=>
77- string(3) "one"
62+ string(3) "foo"
63+ [1]=>
64+ string(3) "bar"
7865 [2]=>
79- string(5) "three"
80- [4]=>
81- string(0) ""
66+ string(3) "baz"
8267}
8368
8469--- UTF-8 and Multi-byte Support ---
@@ -90,7 +75,7 @@ array(2) {
9075}
9176array(2) {
9277 [3]=>
93- string(23 ) "PHP 8.7" عالیه 🚀"
78+ string(18 ) "PHP 8.7 café 🚀"
9479 [4]=>
9580 string(31) "یک ایموجی دیگر 🚀"
9681}
0 commit comments