Answer the question
In order to leave comments, you need to log in
How to convert two dimensional array to one dimensional PHP?
Hello.
I've been breaking my head for a couple of hours, I just can't figure out how to solve a seemingly banal problem. I have this two dimensional array:
$arr = Array(
0 => Array(
0 => 'name 0',
1 => 'name 1',
2 => 'name 2'
),
1 => Array(
0 => 100,
1 => 200,
2 => 300
)
);
$arr = Array(
0 => Array(
0 => 'name 0',
1 => 100,
),
1 => Array(
0 => 'name 1',
1 => 200,
),
2 => Array(
0 => 'name 2'
1 => 300
)
);
Answer the question
In order to leave comments, you need to log in
Exactly the array you want
$arrOne = Array(
0 => Array(
0 => 'name 0',
1 => 'name 1',
2 => 'name 2'
),
1 => Array(
0 => 100,
1 => 200,
2 => 300
)
);
$arrTwo = array();
foreach ($arrOne as $keys => $names) {
foreach ($names as $key => $name) {
$arrTwo[$key][] = $name;
continue;
}
}
var_dump($arrTwo);
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question