tomtimms Posted April 1, 2010 Share Posted April 1, 2010 I have a form and want to take the input (seperated by commas) and store it into an array. Would I just use an explode to store it as an array? $trimmed_up = explode(",", $trimmed); I then want to that array and compare it to another one and show the differences. $array1 = $trimmed_up; $array2 = $trimmed_up2; $compare = array_diff($array1, $array2); would this be the way to do it? Link to comment https://forums.phpfreaks.com/topic/197246-php-string-to-array/ Share on other sites More sharing options...
andrewgauger Posted April 1, 2010 Share Posted April 1, 2010 That is the way I'd do it, but I wouldn't define intermediate $array1 and $array 2, I'd just: $compare = array_diff($trimmed_up, $trimmed_up2); I the $compare would contain only the elements that are in one but not the other. Link to comment https://forums.phpfreaks.com/topic/197246-php-string-to-array/#findComment-1035389 Share on other sites More sharing options...
tomtimms Posted April 1, 2010 Author Share Posted April 1, 2010 how would I do a comparison from a query to a string? I have tried so many different ways and can't get it to work right. $trimmed_up = explode(",", $trimmed); \\taking my search box and exploding each value by comma \\my query $query = "select * from site_keywords WHERE keyword IN('" . join("','", $trimmed_up) ."') AND status='1' AND sid='3' ORDER BY id"; $result = mysql_query($query); $myresult = mysql_fetch_array($result); $compare = array_diff($trimmed_up, $myresult); print_r($compare); ive been at this for awhile now, any idea on where to begin would be nice. Link to comment https://forums.phpfreaks.com/topic/197246-php-string-to-array/#findComment-1035416 Share on other sites More sharing options...
andrewgauger Posted April 3, 2010 Share Posted April 3, 2010 $query = "select * from site_keywords WHERE keyword IN(implode('", "',array_map('mysql_escape_string', $trimmed_up))) AND status='1' AND sid='3' ORDER BY id"; http://php.net/manual/en/function.implode.php example #4 Link to comment https://forums.phpfreaks.com/topic/197246-php-string-to-array/#findComment-1036280 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.