<?php
// Assuming data coming from database is in 1 row.
$data = array
(
'table_nightclub_1' => 'Y',
'table_nightclub_2' => 'N',
'table_nightclub_3' => 'N',
'table_nightclub_4' => 'Y',
'table_nightclub_5' => 'N',
'table_nightclub_6' => 'N',
'table_nightclub_7' => 'Y',
'table_nightclub_8' => 'N',
'table_nightclub_9' => 'N',
'table_nightclub_10' => 'Y',
);
echo
implode // Step 4 : Implode them.
(
' / ',
array_map // Step 3 : Drop the textual part of the keys.
(
function($value)
{
return substr($value, strlen('table_nightclub_'));
},
array_keys // Step 2 : Get the keys from the remaining 'Y's.
(
array_filter // Step 1 : Remove 'N's from array.
(
$data,
function($value)
{
return 'N' != $value;
}
)
)
)
);
Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.
Have a better answer? Share it in a comment.
From novice to tech pro — start learning today.
Old style equivalent.
Open in new window