Hi
How can I search JSON variable than return the exact value that matches the search?
I’m making a email client and email services have different names for there inbox but usually always contains “inbox”
Hers how far I got but it does not work correctly:
$folders = $imap->getFolders();
function strposa($haystack, $needle, $offset=0) {
if(!is_array($needle)) $needle = array($needle);
foreach($needle as $query) {
if(strpos($haystack, $query, $offset) !== false) return true; // stop on first true result
}
return false;
}
$array = json_encode($folders, JSON_PRETTY_PRINT);
var_dump(strposa($params['mailbox'], $array));
So $array
contains in this instance:
{
"Calendar": [],
"Calendar\/Birthdays": [],
"Calendar\/United Kingdom holidays": [],
"Contacts": [],
"Conversation History": [],
"Deleted Items": [],
"Drafts": [],
"INBOX": [],
"Journal": [],
"Junk Email": [],
"Notes": [],
"Outbox": [],
"Sent Items": [],
"Tasks": []
}
and $params['mailbox']
contains “INBOX” but the function reruns bool(false)
If I change $arrary
to $array = array("Junk","Sent","INBOX");
it finds “INBOX”.
Any ideas?
Thanks in advance.