Tonic-_- Posted June 26, 2009 Share Posted June 26, 2009 Any ideas? I tried a few ways and keep getting Notice: Array conversion to string line blah blah (used foreach) Quote Link to comment https://forums.phpfreaks.com/topic/163805-solved-converting-an-array-to-strings/ Share on other sites More sharing options...
.josh Posted June 26, 2009 Share Posted June 26, 2009 well it kind of depends on the format of the string and the array (multi-dim array?) you might find implode to be all you really need. Quote Link to comment https://forums.phpfreaks.com/topic/163805-solved-converting-an-array-to-strings/#findComment-864287 Share on other sites More sharing options...
Tonic-_- Posted June 26, 2009 Author Share Posted June 26, 2009 Ok, i'm trying to build an array to convert each one to a string in for a comparison on a check. Basically I want to check something against strings like 3, 5, 7, a, b I tried to do it like $var = array("3", "5", "7"); $strings = explode(",", $var); foreach ($strings as $string) { //nothing decided yet } But let me do some more research with implode. Quote Link to comment https://forums.phpfreaks.com/topic/163805-solved-converting-an-array-to-strings/#findComment-864293 Share on other sites More sharing options...
.josh Posted June 26, 2009 Share Posted June 26, 2009 function compareStringToArray($string, $array, $ordered = true) { $string = str_replace(' ','',$string); if ($ordered == true) { if ($string == implode(',',$array)) return true; } else { $string = explode(',',$string); if (count(array_merge(array_diff($string,$array),array_diff($array,$string))) == 0) return true; } // in if..else $ordered return false; } // end compareStringToArray Quote Link to comment https://forums.phpfreaks.com/topic/163805-solved-converting-an-array-to-strings/#findComment-864318 Share on other sites More sharing options...
Tonic-_- Posted June 26, 2009 Author Share Posted June 26, 2009 Thanks. Quote Link to comment https://forums.phpfreaks.com/topic/163805-solved-converting-an-array-to-strings/#findComment-864323 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.