Q:

Generate 2 arrays from an array

i have an array like this, with x-coordinate and y-coordinate forming an individual entry. 
$polygon = array("10 0", "20 5", "15 15", "22 15");

Now how can i break this array into 2 different arrays, such that all x-coordinates will fall into one array and all y-coordinates will fall into another array, like this:
$x = array(10, 20, 15, 22);
$y = array(0, 5, 15, 15);

A:

$x = $y = array();
$polygon = array("10 0", "20 5", "15 15", "22 15");
foreach ($polygon as $coor) {
    list($x[], $y[]) = explode(' ', $coor);
}

This will do the trick :)
And to combine them back:
//assuming that $x and $y have the same number of items
for ($i = 0; $i<count($x); $i++) {
    $polygon[] = $x[$i] .' ' .  $y[$i];
}

