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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T07:09:49+00:00 2026-05-23T07:09:49+00:00

I have some inputs that I need to process from a form. The #

  • 0

I have some inputs that I need to process from a form. The # of inputs from a form depends on the number of languages in my application. For example, lets say I support english and french:

$input = array(
  'name_1' => 'Some input in english',
  'content_1' => 'Some long text in english',
  'name_2' => 'Some input in french',
  'content_2' => 'Some long text in french'
);

…Where ‘1’ and ‘2’ are the IDs of english and french respectively. What I want to do is explode the strings:

foreach($input as $key=>$val)
{
  $exploded = explode('_', $key);
  $arr = $exploded[1];
  $key = $exploded[2];
}

..And then push them to separate arrays. Keep in mind that there could be 2 languages, or 10, so just initializing 2 arrays and checking for ‘1’ or ‘2’ as the $key won’t work.

How can I push the values of each to an array so that I end up with an array that look something like this?

$results = array( '1' => array('name' => 'Some input in english', 'content' => 'Some long text in english'), '2' => array('name' => 'Some input in french', 'content' => 'Some long text in french');

Thanks in advance. One idea I had was to initialize 2 arrays based off a count of unique key values, but wanted to check first to see if there is a “right” way to do this for a function already there for something like this.

  • 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-23T07:09:50+00:00Added an answer on May 23, 2026 at 7:09 am

    Would something like this work for you?

    $results = array();
    foreach($input as $key=>$val)
    {
      $exploded = explode('_', $key);
      $results[$exploded[1]][$exploded[0]] = $val;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm working on an application that needs to accept posted data from a form
We have to store data from some flat files that is created using IBM's
I need to do some Natural Language Processing on various text inputs from user
I'm writing some code that needs to process an arbitrary number of lists of
We have some input data that sometimes appears with &nbsp characters on the end.
I have a dl containing some input boxes that I clone with a bit
I have a design issue that I would appreciate some input on. I would
I have some dynamically created inputs which are not server-side controls. I want to
I have a challenge I need some input on. I am currently recruiting programmers
On a website if I have a form where the user can input some

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.