I was working on........something and I thought I'd tidy up the output a little bit.....*cough*
Anyways, I have two arrays like this,
[syntax=text]
Array (
[0] => Zero
[1] => One
)
Array (
[0] => 0
[1] => 1
)
[/syntax]
But now, I want to output it like,
[syntax=text]
Array(
[0] => Array(
[0] => "Zero"
[1] => 0
)
[1] => Array(
[0] => "One"
[1] => 1
)
)
[/syntax]
But I have no idea how I would merge the values with the same key, if that makes sense. I looked into array_merge which doesn't work. I also looked into array_merge_recursively which didn't seem to do anything different.
So, any help on this?
PHP Merge values with same key
Re: PHP Merge values with same key
I cant think of a way other than using a for loop. There probably is a function that does this.
As an example
[syntax=php]for ($i = 0; $i < $total; ++$i){
$new_array[$i] = array($top_array[$i], $bottom_array[$i]);
}[/syntax]
would do that.
There is most likely a better way though !
As an example
[syntax=php]for ($i = 0; $i < $total; ++$i){
$new_array[$i] = array($top_array[$i], $bottom_array[$i]);
}[/syntax]
would do that.
There is most likely a better way though !
Re: PHP Merge values with same key
Hmm, I'll have to try it out. But that would mean that I'd have three loops for each request. Which looks rather odd.
Also, why is this in General Chat?
Also, why is this in General Chat?