Jump to content

array, str_replace() problem


darwin_tech

Recommended Posts

Hi,

 

I am converting a mysqli function to mysql SELECT strings.

 

I basically have two arrays (I include with only one item a piece below for clarity). I want to replace the '?' in the first array values with the value in the second array. I know this should be an easy one and I'm missing something simple...

 

Any help much appreciated.

 


$parts = array('AND (taxon.Genus LIKE ?)');

$params = array(' wasmannia%');

$arrayCount = count($parts);

for ($i = 0; $i < $arrayCount; ++$i) {
	str_replace('?', $params[$i], $parts[$i]);
}

Link to comment
https://forums.phpfreaks.com/topic/232181-array-str_replace-problem/
Share on other sites

hey, that's a nice solution.

 

I just got a version of my code to work (below). Thanks for the help - always better to have more than one solution ;)

 


$parts = array('AND (taxon.Genus LIKE ?)');

$params = array(' wasmannia%');

$arrayCount = count($parts);

$mysqlParts = array();

for($i=0;$i<count($params);$i++) {
    $mysqlParts[] = str_replace("?",$params[$i],$parts[$i]);
}


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.