Jump to content

PHP String To Array


tomtimms

Recommended Posts

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

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.