I have 5 arrays each array contains 10 values, I want to invert these arrays into 10 arrays and each array contains 5 values using php?

For Example:

$array_1 = [1,'a','b','c','d','e','f','g','h','i'];
$array_2 = [2,'aa','bb','cc','dd','ee','ff','gg','hh','ii'];
$array_3 = [3,'aaa','bbb','ccc','ddd','eee','fff','ggg','hhh','iii'];
$array_4 = [4,'aaaa','bbbb','cccc','dddd','eeee','ffff','gggg','hhhh','iiii'];
$array_5 = [5,'aaaaa','bbbbb','ccccc','ddddd','eeeee','fffff','ggggg','hhhhh',   
'iiiii'];

Using PHP Script I want to convert it into

$array_1 = [1,2,3,4,5];
$array_2 = ['a','aa','aa a','aa aa','aa aa a'];
$array_3 = ['b','bb','bb b','bb bb','bb bb b'];
$array_4 = ['c','cc','cc c','cc cc','cc cc c']; 
$array_5 = ['d','dd','dd d','dd dd','dd dd d']; 
$array_6 = ['e','ee','ee e','ee ee','ee ee e'];
.
...
$array_10 = ['i','ii','iii','iiii','iiiii'];

Can anyone provide me a solution for that.

Answers


Simply you can use array_map like as

$array_1 = [1,'a','b','c','d','e','f','g','h','i'];
$array_2 = [2,'aa','bb','cc','dd','ee','ff','gg','hh','ii'];
$array_3 = [3,'aaa','bbb','ccc','ddd','eee','fff','ggg','hhh','iii'];
$array_4 = 
[4,'aaaa','bbbb','cccc','dddd','eeee','ffff','gggg','hhhh','iiii'];
$array_5 =
[5,'aaaaa','bbbbb','ccccc','ddddd','eeeee','fffff','ggggg','hhhhh',   
'iiiii'];

$result = array_map(null,$array_1,$array_2,$array_3,$array_4,$array_5);
print_r($result);

Demo


Need Your Help

Windows API Programming Startup

winapi

I want to learn windows API and PInvoke methods just like MesseageBeep in User32.dll.

Troubleshooting JSONException: End of input at character 0

java android json

I am doing a search on Active.com using their API and currently my search is getting stuck at this error : org.json.JSONException: End of input at character 0. I am a newbie,Any help is appreciated.