Search the blog

This code takes an associative array and converts it to a string using a separator. It preserves the keys too.

$array = ['foo-1' => 'Bar 1', 'foo-2' => 'Bar 2'];

$separator = PHP_EOL; // New line

echo urldecode(http_build_query($array, '', $separator));

// Outputs: 
// foo-1=Bar 1
// foo-2=Bar 2
Tim Bennett is a Leeds-based web designer from Yorkshire. He has a First Class Honours degree in Computing from Leeds Metropolitan University and currently runs his own one-man web design company, Texelate.