Jump to content

Recommended Posts

I'm totally stumped...!!!

 

Currently I have:

Array ( [0] => row1 [1] => row2 ) 
Array ( [0] => 17240475 [1] => 17240475 ) 
Array ( [0] => 28.92 [1] => 165.01 ) 
Array ( [0] => 2 [1] => 1 ) 
Array ( [0] => 62.00 [1] => 165.01 ) 

 

OR

Array ( [0] => Array ( [0] => row1 [1] => row2 ) [1] => Array ( [0] => 17240475 [1] => 17240475 ) [2] => Array ( [0] => 28.92 [1] => 165.01 ) [3] => Array ( [0] => 2 [1] => 1 ) [4] => Array ( [0] => 62.00 [1] => 165.01 ) )

 

 

I need this to be grouped by key so that it's like this:

 

[0] => row1

[0] => 17240475

[0] => 28.92

[0] => 2

[0] => 62.00

 

[1] => row2

[1] => 17240475

[1] => 165.01

[1] => 1

[1] => 165.01

 

 

Is it even possible...?

Should it be even in a multidimensional array format...?

Or am I going about this the wrong way?

 

Any help is appreciated, Thank you very much!

 

Link to comment
https://forums.phpfreaks.com/topic/277625-multidimensional-array/
Share on other sites

try

$data = Array ( 
    0 => Array ( 
        0 => 'row1', 
        1 => 'row2' 
        ) ,
    1 => Array ( 
        0 => 17240475, 
        1 => 17240475 
        ) ,
    2 => Array ( 
        0 => 28.92 ,
        1 => 165.01 
        ) ,
    3 => Array ( 
        0 => 2 ,
        1 => 1 
        ) ,
    4 => Array ( 
        0 => 62.00, 
        1 => 165.01 
        ) 
    );
$new = array();

foreach ($data as $arr) {
    foreach ($arr as $k => $v) {
        $new[$k][] = $v;
    }
}

echo '<pre>',print_r($new, true),'</pre>';

 

$data = Array (

0 => Array (

0 => 'row1',

1 => 'row2'

) ,

1 => Array (

0 => 17240475,

1 => 17240475

) ,

2 => Array (

0 => 28.92 ,

1 => 165.01

) ,

3 => Array (

0 => 2 ,

1 => 1

) ,

4 => Array (

0 => 62.00,

1 => 165.01

)

);

$new = array();

 

foreach ($data as $arr) {

foreach ($arr as $k => $v) {

$new[$k][] = $v;

}

}

 

echo '<pre>',print_r($new, true),'</pre>';

 

 

This looks like it would work...

But I forgot to mention the arrays are coming in as variables...how would I do this...?

 

$data = Array (

0 => $row

) ,

1 => $id

) ,

2 => $stat1

) ,

3 => $stat2

) ,

4 => $stat4

)

);

$new = array();

 

foreach ($data as $arr) {

foreach ($arr as $k => $v) {

$new[$k][] = $v;

}

}

 

echo '<pre>',print_r($new, true),'</pre>';

 

 

 

Thanks!

Don't get me wrong, it helped ALOT.

They are one in the same, because the values are coming from a form, I'm not sure how to explain it.

And I can't just paste code because it's too sensitive, it would be a lot of work to "clean it".

 

I used to come here LONG time ago to get quality help. If I knew I was going to get criticized, I would have never returned.

If that's what I'm getting now, no thanks.

Great way to discourage and drive away people!

 

I'll figure out a solution using another method.

They are one in the same, because the values are coming from a form, I'm not sure how to explain it.

What does that even mean?

 

If the values are posted in a form, they're in $_POST. And you can use Barand's code exactly. What you're trying to accomplish isn't clear at all though.

 

I used to come here LONG time ago to get quality help. If I knew I was going to get criticized, I would have never returned.

If that's what I'm getting now, no thanks.

Great way to discourage and drive away people!

Wah wah wah. You're asking us to devote our time for free to help you, and you're not asking decent questions. Imagine if your boss came to you and said "Make me a website that displays the current time", and you did it, then he said "Oh but really I meant the time in every time zone and make it display daylight savings time, and make the background cycle through random colors. Wait nevermind since you didn't do it the first time I'll just hire someone else, and not pay you at all."

 

Kind of whiny eh?

  • 3 weeks later...

Excuse me...! Who's the one whinning??? 

Sorrrry for "asking you to devote your free time"...but I never recall asking YOU to devote your precious time!

Wow you people are on some high horse! If you're so worried about your free time, why are you even in a "community forum"...???

Or perhaps the status of this forum has changed since the last time I was in here...?

Clearly you enjoy your free time bashing, flaming, and criticizing....

Sheeesh, I was stumped, and attempted to throw the issue out there in the "community"...but clearly this was the wrong venue...

...I missed where it said, "for the chosen who are willing to devote their time to the minions."

I was looking for some professionals....

 

 

"Make me a website that displays the current time", and you did it, then he said "Oh but really I meant the time in every time zone and make it display daylight savings time, and make the background cycle through random colors. Wait nevermind since you didn't do it the first time I'll just hire someone else, and not pay you at all."

 

What does this even have to do with what I'm talking about??? In your example, he would be your BOSS, it would be his prerogative. End of subject.

 

 

Would you kids like to continue with the flaming...?

Guest
This topic is now closed to further replies.
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.