Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8406273
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T23:03:54+00:00 2026-06-09T23:03:54+00:00

$search = array(‘A’, ‘B’, ‘C’, ‘D’, ‘E’); $replace = array(‘B’, ‘C’, ‘D’, ‘E’, ‘F’);

  • 0
 $search  = array('A', 'B', 'C', 'D', 'E');
 $replace = array('B', 'C', 'D', 'E', 'F');
 $subject = 'A';
 $trans = array('A' => 'B','B'=>'C','C'=>'D','D'=>'E','E'=>'F');
 echo str_replace($search, $replace, $subject);
 echo "<br/>";
 echo strtr($subject,$trans);

 Output: F
         B

When using str_replace I get F, using strtr i get B

As far I am getting this, for str_replace: It replaces from left to right, so A gets replaced with B without marking the position was already replaced, so again finds B which is replaced by C and so on to get value F.

For strtr: I replaces A with B and remembers it has replaced at that position,

Am i getting this correctly? could someone explain to me?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T23:03:56+00:00Added an answer on June 9, 2026 at 11:03 pm

    Yes, that is correct. str_replace() does its replacements sequentially, whereas strtr() works through each character in the string and replaces it only once.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

is there a similar function in python that takes search(array) and replace(array) as a
i want to know how to get all fields value search by array. i
If i have an array $output that looks like this, how can i search
I am using binary search to search a number from a sorted array of
I'm using this function to search the (highest) array key when a value of
How can I call eBay and request it to return search results array? This
I need to write effective and quick method to search byte array for given
I was wondering if anyone could show me how to search this array that
Possible Duplicate: byte[] array pattern search I am trying to write a simple compression
Why people usually do binary search instead of triple search (divide the array into

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.