-
Notifications
You must be signed in to change notification settings - Fork 0
/
country.php
58 lines (46 loc) · 1.62 KB
/
country.php
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
<?php
$suggestions = ['India', 'Pakistan', 'Nepal', 'UAE', 'Iran', 'Bangladesh'];
$data = [];
if($_SERVER['REQUEST_METHOD'] == 'POST')
{
foreach($suggestions as $suggestion)
{
if(strpos(strtolower($suggestion), strtolower($_POST['term'])) !== false)
{
$data[] = $suggestion;
}
}
}
else
{
foreach($suggestions as $suggestion)
{
if(strpos(strtolower($suggestion), strtolower($_GET['term'])) !== false)
{
$data[] = $suggestion;
}
}
}
header('Content-Type: application/json');
echo json_encode(['suggestions' => $data]);
// $suggestions = [['tag'=>'India','value'=>34], ['tag'=>'Pakistan','value'=>12], ['tag'=>'Nepal','value'=>43], ['tag'=>'UAE','value'=>11], ['tag'=>'Iran','value'=>21], ['tag'=>'Bangladesh','value'=>22],['tag'=>'Italy','value'=>23], ['tag'=>'Australia','value'=>134]];
// $data = [];
// foreach($suggestions as $suggestion)
// {
// if(strpos(strtolower($suggestion['tag']), strtolower($_GET['term'])) !== false) {
// $data[] = $suggestion;
// }
// }
// header('Content-Type: application/json');
// echo json_encode(['suggestions' => $data]);
// $suggestions = ['India', ['tag'=>'Pakistan','value'=>12], 'Nepal', ['tag'=>'UAE','value'=>11], ['tag'=>'Iran','value'=>21], ['tag'=>'Bangladesh','value'=>22],['tag'=>'Italy','value'=>23], 'Australia'];
// $data = [];
// foreach($suggestions as $suggestion)
// {
// $value = is_array($suggestion)? $suggestion['tag']: $suggestion;
// if(strpos(strtolower($value), strtolower($_GET['term'])) !== false) {
// $data[] = $suggestion;
// }
// }
// header('Content-Type: application/json');
// echo json_encode(['suggestions' => $data]);