我正在从数据库中检索一个数组值,它保存多维数组..我想添加
|
在array..i的两个成员值之间的尝试了基本的内爆函数,最后提到了我试过的内容..
我在下面提到循环
$sql = "SELECT `categories` FROM `jos_js_res_record` WHERE `categories` LIKE '%Autumn Market Session%' OR `categories` LIKE '%Farmer Market Profiles%' OR `categories` LIKE '%Spring Market Session%' OR `categories` LIKE '%Summer Market Session%' OR `categories` LIKE '%Winter Market Session%' ORDER BY `user_id`";
$db->setQuery( $sql );
$unserial = $db->loadObjectList();
foreach ($unserial as $dataElement) {
$categories = unserialize($dataElement->categories);
if (is_array($categories)) {
foreach ($categories as $unserKey => $unserailData) {
print $unserailData;
}
}
echo '<br />';
}
我在第二个循环中尝试了以下代码行,但是显示错误
$comma_separated = implode(",", $unserailData);
请指导我如何在第二个数组 $ unserailData 中内爆值?
$ unserailData中的数据如下所示
夏季市场会议
夏季市场会议
夏季市场会议秋季市场会议
夏季市场会议秋季市场会议
答案 0 :(得分:0)
如果我正确地阅读您的请求,以下内容应该有效:
$sql = "SELECT `categories` FROM `jos_js_res_record` WHERE `categories` LIKE '%Autumn Market Session%' OR `categories` LIKE '%Farmer Market Profiles%' OR `categories` LIKE '%Spring Market Session%' OR `categories` LIKE '%Summer Market Session%' OR `categories` LIKE '%Winter Market Session%' ORDER BY `user_id`";
$db->setQuery( $sql );
$unserial = $db->loadObjectList();
foreach ($unserial as $dataElement) {
$categories = unserialize($dataElement->categories);
if (is_array($categories)) {
echo implode('|', $categories);
} elseif (is_string($categories)) {
echo $categories;
}
echo '<br />';
}
答案 1 :(得分:0)
我做了以下技巧,但提到的代码@Robbie更干净,所以我用他的代码替换我的代码。
我做了这个伎俩
foreach ($unserial as $dataElement) {
$categories = unserialize($dataElement->categories);
if (is_array($categories))
{
foreach ($categories as $unserKey => $unserailData) {
$arr2[] = $unserailData;
}
$imploded = implode(" | ", $arr2);
print_r($imploded);
$arr2 = array();
}
else{
echo "Category not stored correctly";
}
echo '<br />';
}