PHP full text search on associative array
<p>I am encrypting and decrypting my MySQL contact table in PHP. That is all fine and everything but I am making the data grid so that it has a single search box that does a full text search on all the columns. The problem now is that the search is being done against the encrypted data and not the original data.</p>

<p>So I am forced to do the full text search in PHP. This requires me to iterate over each row, but I am doing this anyway because I need to decrypt it.</p>

<p>My concern lies with the speed at which my code does the full text search, I want to know if there is a better, faster way to do this? </p>

<pre><code>$result = Some PDO query that does a PDO::FETCH_ASSOC, query has about 8 columns
$searchPhrase = strtolower($searchPhrase);
$aes = new AES(DATABASE_KEY, DATABASE_IV);
$count = count($result);

for($ii = 0; $ii &lt;$count; $ii++ )
{
    $result[$ii]["ContactName"] = $aes-&gt;Decrypt($result[$ii]["ContactName"]);
    $result[$ii]["ContactDescription"] = $aes-&gt;Decrypt($result[$ii]["ContactDescription"]);
    /*More encrypted columns*/


    if (!empty($searchPhrase)) //Only do search when search phrase not empty
    {        
        $filterRow = array_slice($result[$ii], 3); // Do not take first 3 columns       
        $data = strtolower(implode("", $filterRow)); //Flaten row as one string, all lowercase
        if (strpos($data, $searchPhrase) === FALSE) //Now doing elimentation from array if not match
            unset($result[$ii]);
    }

}
</code></pre>