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

  • SEARCH
  • Home
  • 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 9073797
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T18:30:05+00:00 2026-06-16T18:30:05+00:00

Solution I am looking for: I would like to rearrange words within the text

  • 0

Solution I am looking for:
I would like to rearrange words within the text string results such that the job title is moved from the end of the string to the beginning of the string for each line item.

Currently, I am retrieving data from an external medical database query ($query). However, I cannot make any changes to the database or to the MySQL query statement itself.

The $query is retrieved and I then place the results in a $data array via the following command:

while($row = mysql_fetch_assoc($query)){$data[] = $row;}

I then change all the job titles to uppercase in the $data array as follows:

$job_01 = 'anesthesiologist';
$job_02 = 'dentist';
$job_03 = 'general practitioner';
$job_04 = 'internist';
$job_05 = 'lawyer';
$job_06 = 'manager';
$job_07 = 'pediatrician';
$job_08 = 'psychiatrist';

$replace_01 = 'ANESTHESIOLOGIST';
$replace_02 = 'DENTIST';
$replace_03 = 'GENERAL PRACTITIONER';
$replace_04 = 'INTERNIST';
$replace_05 = 'LAWYER';
$replace_06 = 'MANAGER';
$replace_07 = 'PEDIATRICIAN';
$replace_08 = 'PSYCHIATRIST';

$searchArray = array($job_01, $job_02, $job_03, $job_04, $job_05, $job_06, $job_07, $job_08);
$replaceArray = array($replace_01, $replace_02, $replace_03, $replace_04, $replace_05, $replace_06, $replace_07, $replace_08);

for ($i=0; $i<=count($data)-1; $i++) {
 $line[$i] = str_ireplace($searchArray, $replaceArray, $data[$i]));
}

The final output is in the following line item text string format:

Example Query results (4 line items)

California Long time medical practitioner  -  ANESTHESIOLOGIST 55yr
New York Specializing in working with semi-passive children - PEDIATRICIAN (doctor) 42yr
Nevada Currently working in a new medical office - PSYCHIATRIST 38yr
Texas Represents the medical-liability industry - LAWYER (attorney) 45yr

I would like to rearrange these results such that I can output the data to my users in the following format by moving the job title to the beginning of each line item as in:

Desired results (usually over 1000 items)

ANESTHESIOLOGIST - California Long time medical practitioner  - 55yr
PEDIATRICIAN - New York Specializing in working with semi-passive children - (doctor) 42yr
PSYCHIATRIST - Nevada Currently working in a new medical office - psychiatrist 38yr
LAWYER - Texas Represents the medical-liability industry - lawyer (attorney) 45yr

Ideally, if possible, it would also be nice to have the age moved to the beginning of the text string results as follows:

Ideal Results

55yr - ANESTHESIOLOGIST - California Long time medical practitioner
42yr - PEDIATRICIAN - New York Specializing in working with semi-passive children - (doctor)
38yr - PSYCHIATRIST - Nevada Currently working in a new medical office - psychiatrist
45yr - LAWYER - Texas Represents the medical-liability industry - lawyer (attorney)
  • 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-16T18:30:07+00:00Added an answer on June 16, 2026 at 6:30 pm

    You could use a regular expression to extract and rearrange the array:

    for ($i=0; $i<=count($data)-1; $i++) {
        $line[$i] = str_ireplace($searchArray, $replaceArray, $data[$i]));
        // variant a, complete line
        if(preg_match_all('/(.*)\s+-\s+(.*)\s+(\d+)yr$/', $line[$i],$matches)) {
            $line[$i] = $matches[3][0].'yr - '.$matches[2][0].' - '.$matches[1][0];
        // variant b, a line with age, but no jobtitle
        } elseif(preg_match_all('/(.*)\s+-\s+(\d+)yr$/', $line[$i],$matches)) {
            $line[$i] = $matches[2][0].'yr - '.$matches[1][0];
        // variant c, no age
        } elseif(preg_match_all('/(.*)\s+-\s+(.*)$/', $line[$i],$matches)) {
            $line[$i] = $matches[2][0].' - '.$matches[1][0];
        }
        // in other cases (no age, no jobtitle), the line is not modified at all.        
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm looking for something like createdb in PostgreSQL or any other solution that would
I am looking for a solution that i would like to get user opened
I am looking for shortest solution for the following problem: I would like to
I would like to read an file into a string. I am looking for
I would like a solution that doesn't include critical sections or similar synchronization alternatives.
I am looking for a solution for PHP and comet. I would like to
I'm looking for solution how can run Ruby script without invoking it directly like
im looking forward for a 3rd part tool/solution that can monitor my server's network
I'm looking for a library (or a cleverer solution) in C or C++ that
I would like to give some kind of indication to the user when text

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.