I don't like counting through arrays. Here's my solution:
$toplevel = true;
$table = array();
foreach ($new as $key => $val) {
if ($toplevel) {
$firstkey = $val;
} else {
$arraylist = explode(',', $val);
foreach ($arraylist as $arrayval) {
$table[$firstkey][$arrayval] = NULL;
}
}
$toplevel = !$toplevel;
}
this exact code should produce:
$table[direction][d1] = NULL
$table[direction][d2] = NULL
$table[direction][d3] = NULL
$table[direction][d4] = NULL
$table[direction][d5] = NULL
$table[direction][d6] = NULL
$table[char][c1] = NULL
$table[char][c2] = NULL
$table[char][c3] = NULL
Now, if what you meant was that you need an array like this:
$table[direction][0] = 'd1';
$table[direction][1] = 'd2';
$table[direction][2] = 'd3';
$table[direction][3] = 'd4';
$table[direction][4] = 'd5';
$table[direction][5] = 'd6';
$table[char][0] = 'c1';
$table[char][1] = 'c2';
$table[char][2] = 'c3';
Let me know. This is actually easier to do than the other, but, from the example you gave, the first solution should provide you with what you need.