Say the data you have is in a file, you'll need to use associative arrays to get the job done!

Code: PHP
$arr = array();
// Read the data an get it into array $data
foreach($data as $v)
{
  list($val,$key) = explode('#',$v);
  if(isset($arr[$key]))
  {
    $arr[$key] .= "$val|";
  }
  else
  {
    $arr[$key] = $val;
  }
}

So you just print out the array $arr to get the desired output.