How combine arrays in this way?
source:
Array ( [0] => Array ( [id] => 3 [title] => book [tval] =
This should work:
$result = array(); foreach($array as $elem) { $key = $elem['id']; if (isset($result[$key])) { $result[$key]['tval'] .= ',' . $elem['tval']; } else { $result[$key] = $elem; } }
This basically groups elements by id, concatenating tvals (separated by ,).
id
tvals
,