Home > database >  compare word with array [closed]
compare word with array [closed]

Time:10-04

<?php

$emails=array
  (
    array("Sender:"=>"Sham","Subject:"=>"Saving Account","Description:"=>"Hello Sir/Madam,Your Saving A/C ********123 is set up and ready for use.", "Date:"=>"10/09/2021"),
    array("Sender:"=>"DEF","Subject:"=>"Loan Documents","Description:"=>"Please submit mentioned documents for verification of your file. Document list is attached","Date:"=>"11/09/2021"),
    array("Sender:"=>"GHI","Subject:"=>"Blood Donation","Description:"=>"Hello,You have registered successfully!!!, Thanks for joining us. You will receive further details shortly","Date:"=>"19/09/2021"),
    array("Sender:"=>"ABC","Subject:"=>"Rotary","Description:"=>"Hello,There is Plantation Program on sunday, we would like to invite you to join with us. Please register on given link so we will send you further details of program","Date:"=>"19/09/2021"),
    array("Sender:"=>"Rakesh","Subject:"=>"Addmission","Description:"=>"Please send your documents for verification.","Date:"=>"14/09/2021")
 
  );
$a=array_column($emails,'Description:');

Search - Bar Question
There is an multidimensional associative array. I extract the values of 'Description' Column. My question is how we compare the specific word with $a array. Suppose if user enter hello, then by comparing with $a array and find in which description there is hello word and print all the details of column(Sender, Subject, Description, Date). Thank you.

CodePudding user response:

There is no function for that action. You need to write it by yourself.

Write function findEmailSettings(string $word):array

and use it to get specific email settings with some word.


But this code structure doesn't look optimal

CodePudding user response:

see my codes

call it
uasort($result, "compareChatRowsByDate");

function compareChatRowsByDate($a, $b): int
{
    if ($a['createdAt'] == $b['createdAt']) {
        return 0;
    } else if ($a['createdAt'] >= $b['createdAt']) {
        return -1;
    } else if ($a['createdAt'] <= $b['createdAt']) {
        return 1;
    }
}

  • Related