str replace - PHP str_replace: Element order in arrays and output result -


this question has answer here:

i using str_replace() function replace values in array , use new value later in mysql query. however, found weird situation can't understand. why these queries aren't returning same output?

the first version of code returns: 214847

<php? $idpage=array(18,21,22); $idcompetition=array(2147,2148,2149);  $idt=str_replace($idpage,$idcompetition,18);  echo $idt; ?> 

and if change order in arrays, result is: 2147

<php? $idpage=array(21,22,18); $idcompetition=array(2148,2149,2147);   $idt=str_replace($idpage,$idcompetition,18);  echo $idt; ?> 

the 2nd query returns required result, , used in code, it's unclear me why first query isn't working correctly.

in real code provide subject of replacement (e.g. 18) reading global variable of page:

global $objpage;     $idt=str_replace($idpage,$idcompetition,$objpage->id); 

thanks.

in first code: str_replace finds first element of $idpage (== '18') in search string (== '18') , replaces '2147', iterates second value of $idpage (== '21'), finds in search string (== '2147' atm) , replaces '2148', iterates third value of $idpage (== '22') , can't find in search string (== '214847' atm).


Comments

Popular posts from this blog

Payment information shows nothing in one page checkout page magento -

tcpdump - How to check if server received packet (acknowledged) -