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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T19:51:18+00:00 2026-05-24T19:51:18+00:00

any particular function or code to put this kind of array data ori [0]

  • 0

any particular function or code to put this kind of array data

ori  [0] => 43.45,33,0,35 [1] => 74,10,0,22 [2] => 0,15,0,45 [3] => 0,0,0,340 [4] => 12,5,0,0 [5] => 0,0,0,0

to

new  [0] => 43.45,74,0,0,12,0 [1] => 33,10,15,0,5,0 [2] => 0,0,0,0,0,0, [3] => 35,22,45,340,0,0

As you can see, the first value from each ori are inserted into the new(0), the second value from ori are inserted into new(1) and so on

  • 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-24T19:51:19+00:00Added an answer on May 24, 2026 at 7:51 pm

    You essentially want to transpose – basically “turn” – an array. Your array elements are strings and not sub arrays, but those strings can be turned into sub arrays with explode() before transposing. Then after transposing, we can turn the sub arrays back into strings with implode() to preserve the formatting you want.

    Basically we want to go through each of your five strings of comma separated numbers one by one. We take each string of numbers and turn it into an array. To transpose we have to take each of the numbers from a string one by one and add the number to a new array. So the heart of the code is the inner foreach(). Note how each number goes into a new sub array, since $i is increased by one between each number: $new[$i++][] =$op;

    foreach($ori as $one) {
        $parts=explode(',',$one);
        $i = 0;
        foreach($parts as $op) {
            $new[$i++][] =$op;
        }
    
    }
    $i = 0;
    foreach($new as $one) {
        $new[$i++] = implode(',',$one);
    }
    
    // print_r for $new is:
    Array
    (
        [0] => 43.45,74,0,0,12,0
        [1] => 33,10,15,0,5,0
        [2] => 0,0,0,0,0,0
        [3] => 35,22,45,340,0,0
    )
    

    Working example

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

Sidebar

Related Questions

Is the following shorthand for $(document).ready ? (function($){ //some code })(jQuery); I see this
Is there any way to find particular C language function's input and output parameters
Is there any particular reason that all data members in a class are private
I would like a reusable function that simply does a BlurEffect on any particular
Is there any particular reason to use one over the other? I personally tend
I'm not committed to any particular GUI tookit or anything - just needs to
Does javascript coding work better with any particular server language?
It seems that SQL Server does not accept numbers formatted using any particular locale.
I've heard that given a programmer with enough time and skill in any particular
Let's say I want to represent \q (or any other particular backslash-escaped character). That

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.