I have an array like this
$list = [];
$list[] = [
"name" => "bill gates",
"os" => "windows"
];
$list[] = [
"name" => "steve jobs",
"os" => "mac"
];
$list[] = [
"name" => "linus torvals",
"os" => "linux"
];
And the I will output this
bill gates > windows, steve jobs > mac, linus torvals > linux
In order to do that, this is what I do
$sentence_parts = [];
foreach($list as $item)
{
$sentence_parts[] = implode(" > ", $item);
}
$sentence = implode(", ", $sentence_parts);
echo $sentence;
It works, but I feel that maybe I could write a much simpler code. Is there a way to minifiy the code? Maybe a one liner?