Solution
You can do it cleanly by joining strings, while using eg. custom associative mapping function, which looks like that:
function array_map_associative($callback, $array){
$result = array();
foreach ($array as $key => $value){
$result[] = call_user_func($callback, $key, $value);
}
return $result;
}
Full example and test
The full solution using it could look like that:
<?php
function array_map_associative($callback, $array){
$result = array();
foreach ($array as $key => $value){
$result[] = call_user_func($callback, $key, $value);
}
return $result;
}
function callback($key, $value){
return $key . '-' . $value;
}
$data = array(
35 => '3',
24 => '6',
72 => '1',
16 => '5',
81 => '2',
);
$result = implode('|', array_map_associative('callback', $data));
var_dump($result);
and the result is:
string(24) "35-3|24-6|72-1|16-5|81-2"
which matches what you expected.
The proof is here: http://ideone.com/HPsVO6
How to get it the easy way?
you mean without loop right ? – Baba Nov 11 '12 at 14:25