I have an array like this.
$array[0] = 'email1';
$array[1] = 'email2';
$array[2] = 'email3';
$array[3] = 'mobile1';
$array[4] = 'mobile2';
$array[5] = 'mobile3';
$array[6] = 'email1_c';
$array[7] = 'email2_c';
$array[8] = 'email3_c';
$array[9] = 'mobile1_c';
$array[10] = 'mobile2_c';
$array[11] = 'mobile3_c';
Now i want to dispay a table like this
--------------------------------
email1 | email1_c
email2 | email2_c
email3 | email3_c
mobile1 | mobile1_c
mobile2 | mobile2_c
mobile3 | mobile3_c
Now when i loop through the array i get this
--------------------------------
email1 | email2
email3 | mobile1
mobile2 | mobile3
email1_c | email2_c
email2_c | mobile1_c
mobile1_c | mobile3_c
Now this is not what i want and i know simple looping wont do what i want. So is there any alternative way to achieve this.
Note : The data given is only sample data. I am actually working in a pre-defined template in wordpress and wordpress simply throw me an object so i can use it. In the backend i have tried everything even sorting but i get the data like above. I need alternative so i can change easily and i dont want to modify default files.
It appears that it depends on an offset value. As you have it shown that value would be six:
$html = "<table>
";
$offset = 6;
for ($i=0; $i<=5; $i++){
$html .= "<tr><td>".$array[$i]."</td><td>".$array[$i + $offset]."</td></tr>
";
}
$html .= "</table>
";
Depending on what you need you might need to dynamically calculate the offset. For example:
$offset = count($array)/2;