Jump to content

[SOLVED] Converting an array to strings.


Tonic-_-

Recommended Posts

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.

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

 

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.