I have two fields that I'm getting from a database table. I want to grab them, split them into an array, sort them and then stick them back together again so I can compare them to see if they are equal. I don't have control over how these get entered into the table. One is just straight characters and the other is comma separated. So, would this be the best solution?:
$var1 = value($sql, $db);
$var1Array = str_split($var1);
sort($var1Array);
$var1 = implode("",$var1Array);
and then the comma separated one...
$var2 = value($sql, $db);
$var2= str_replace(" ","",$var2;
$var2 = str_replace(",","",$var2);
$var2Array = str_split($var2);
sort($var2Array);
$var2 = implode("",$var2Array);
and then compare then they are in the same order and format to see if they are the same. Is there a better or easier way to do this.
Note: value($sql, $db) is a function that I have that returns a single value from a sql statement. I this case:
SELECT cad
FROM CompositeTable
WHERE loc = '$loc'
AND accDate = '0000-00-00'
AND acctNum = '$accnum'