-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsearch_in_array.php
More file actions
43 lines (31 loc) · 942 Bytes
/
search_in_array.php
File metadata and controls
43 lines (31 loc) · 942 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
<?php
function array_stristr($array, $search)
{
if (stristr(implode(";", $array), $search))
{
return true;
}
else
{
return false;
}
}
function array_find($array, $search, $getKey = false)
{
if (stristr(implode(";", $array), $search))
{
$value = strrev(stristr(strrev(stristr(implode(";", $array), $search, true)), ";", true)) . stristr(stristr(implode(";", $array), $search, false), ";", true);
if ($getKey)
$value = array_flip($array)[$value];
return $value;
}
else
{
return false;
}
}
$array = ["Herro", "Hero", "Hello", "EHLO"];
$search = "lo";
if (array_stristr($array, $search))
echo $search . " was found in " . implode(";", $array) . "\n";
echo "key:" . array_find($array, $search) . "\n";