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 4342620
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T11:38:32+00:00 2026-05-21T11:38:32+00:00

I have two issues I was hoping to get help on: Combine two arrays

  • 0

I have two issues I was hoping to get help on:

  1. Combine two arrays into one string
    and add some formatting
  2. insert the new string into a
    specific spot in a bigger string.

I have two arrays:

$array_1 =  array("100","200","300");
$array_2 = array("abc","def","ghi");

$result = array_merge($array_1, $array_2);

foreach ($result as $val){
//NEED HELP HERE  create a string that adds a "mac=" to the beginning of the current $val and adds a "/n" to the end of the current value.
}

The above should somehow create the string below:

 $my_string = "mac=100/n
              mac=200/n
              mac=300/n
               mac=abc/n
              mac=def/n
              mac=ghi/n";

Now for Part #2

I have a current string that was created already:

$current_String = "[MACS]/n
                   mac=blah1/n
                   mac=blah2/n
                   mac=blah3/n
                   [SERVICES]";

My last issue is to replace everything between [MACS]/n and [SERVICES] with $my_string

So I should end up with:

$updated_String = "[MACS]/n
                  mac=100/n
                  mac=200/n
                  mac=300/n
                  mac=abc/n
                  mac=def/n
                  mac=ghi/n
                  [SERVICES]";

Any help or insight would be greatly appreciated.

  • 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-05-21T11:38:33+00:00Added an answer on May 21, 2026 at 11:38 am

    This should work:

    $array_1 =  array("100","200","300");
    $array_2 = array("abc","def","ghi");
    
    $result = array_merge($array_1, $array_2);
    
    $myString = "[MACS]/n\nmac=" . implode($result, "/n\nmac=") . "/n\n[SERVICES]";
    
    //replace in other string
    $macsIndex = strrpos($currentString, "[MACS]");
    $servicesIndex = strrpos($currentString, "[SERVICES]");
    $currentString = substr($currentString, 0, $macsIndex) . $myString . substr($currentString, servicesIndex+10);
    

    Outputs:

    [MACS]/n
    mac=100/n
    mac=200/n
    mac=300/n
    mac=abc/n
    mac=def/n
    mac=ghi/n
    [SERVICES]
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two issues in this google chart. I want to either get rid
I have an issue with NSMutableArray and scope I am hoping to get some
I need to override styles for two EditText instances. I have two issues regarding
I have found many people with simliar issues but no soultions...basically I have two
I have following fiddle: http://jsfiddle.net/BFSH4/ As you see there are two issues: The h1
I have the following issue: A java object contains two arrays of core datastore
I have two issues I have ignored so far, but I will really appreciate
I have two issues. I have Ubuntu 10.10 and I have installed git server
I have two AsyncTasks that I am using, one is called up after a
I have a small issue I was hoping somebody could help me with. I

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.