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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T09:10:13+00:00 2026-06-11T09:10:13+00:00

Here are the variables: $ids = array_unique($_POST[‘id’]); $total_ids = count($ids); $name = $_POST[‘name’]; $positions

  • 0

Here are the variables:

$ids = array_unique($_POST['id']);
$total_ids = count($ids);

$name = $_POST['name'];

$positions = $_POST['position'];
$total_positions = count($positions);

This is what the print_r shows:

[id] => Array ( 
    [0] => 3 
    [1] => 7 ) 

[name] => Array ( 
    [0] => George 
    [1] => Barack ) 

[position] => Array ( 
    [1] => Array ( 
        [0] => 01 
        [1] => 01 ) 
    [2] => Array ( 
        [0] => 01 
        [1] => 01 
        [2] => 01 ) )

This is the result which I would like to get on refresh/submit:

[id][0];
    [name][0];
        [position][1][0];[position][1][1]
[id][1];
    [name][1];
        [position][2][0];[position][2][1];[position][2][2]

To make the wanted result well clear:

User with [id][0] 
    is called [name][0] 
        and works at [position][1][0];[position][1][1]
BUT

User with [id][1]
    is called [name][1];
        and works at [position][2][0];[position][2][1];[position][2][2]

Please note that [position]s starts with [1], not [0].

How could I display the arrays in the order I showed?

  • 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-11T09:10:15+00:00Added an answer on June 11, 2026 at 9:10 am

    I’m not 100% sure I understand what you need, but to try to match the final-example of the output you displayed I came up with the following:

    // iterate through each of the `$ids` as a "user"
    foreach ($ids as $key => $value) {
        // output the user's ID
        echo 'User with ' . $value;
        if (isset($name[$key])) {
            // output the user's name
            echo ' is called ' . $name[$key];
        }
        if (isset($position[$key + 1])) {
            // output a ';'-delimited list of "positions"
            echo ' and works at ';
            $positions = '';
            // the `$positions` array starts with index 1, not 0
            foreach ($position[$key + 1] as $pos) {
                $positions .= (($positions != '') ? ';' : '') . $pos;
            }
            echo $positions;
        }
        echo '<br />';
    }
    

    This will give output similar to:

    User with 1 is called Bill and works at pos1;pos2;pos3
    User with 14 is called Jill and works at pos134

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

Sidebar

Related Questions

I'm sure this depends heavily on a few variables. Here are the ones I
Here is my code: $(document).ready(function(){ //These variables are for loading more posts var create_ptr
Here is the question: write a method that swaps two variables. These two variables
i have an old codebase here, where they used protected member variables. Whether or
I am trying to insert php variables into javascript. Here is the broken code:
I would like to access class variables with for loop, here is my simple
The following code utilizes CreateProcess to run commands with environmental variables. Here, it tries
I have array of products IDs. I have to make query like this: SELECT
Here will explain in detail: I have public class Season { #region Public Variables
A similar question was asked here: PHP variable like $myvar-test is not valid? And

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.