Reputation: 481
I have this array of items:
$tabslist = array('upload' => 'Upload File', 'pending_files' => 'Pending Files', 'call_data' => 'Call Data', 'services_data' => 'Services Data');
and i want to be able to find one of these items, i have tried using:
$title = array_search($_GET["tab"], $tabslist);
the value of $_GET["tab"]
is 'upload'
so i want $title
to be 'Upload File'
Upvotes: 1
Views: 38
Reputation: 4066
simply use isset function
$tabslist = array('upload' => 'Upload File', 'pending_files' => 'Pending Files', 'call_data' => 'Call Data', 'services_data' => 'Services Data');
$title = isset($tablist[$_GET["tab"]]) ? $tablist[$_GET["tab"]] : "";
UPDATE
as Hasse said in comment you can convert $_GET["tab"]
to lowercase to insure correctness
$_GET['tab'] = strtolower( $_GET['tab'] );
$title = isset($tablist[$_GET["tab"]]) ? $tablist[$_GET["tab"]] : "";
Upvotes: 2