我已将一些数据插入数据库,结果是数组,因此我需要将结果转换为字符串
这是我的结果
array(2) {
[0]=> array(1) {
["file_name"]=> string(38) "3848765-wallpaper-images-download1.jpg"
}
[1]=> array(1) {
["file_name"]=> string(43) "6941202-smile-desktop-background-103791.jpg"
}
}
我想要
3848765-wallpaper-images-download1.jpg,6941202-smile-desktop-background-103791.jpg
任何转换方式? 提前谢谢!!!!!
答案 0 :(得分:4)
试试这个有效
$data = [
["file_name" => "3848765-wallpaper-images-download1.jpg"],
['file_name' => "6941202-smile-desktop-background-103791.jpg"]
];
echo implode(', ', array_column($data, 'file_name'));
答案 1 :(得分:2)
没有转换器。你需要使用循环(例如foreach)并自己创建字符串。
<?php
$data = [
["file_name" => "3848765-wallpaper-images-download1.jpg"],
['file_name' => "6941202-smile-desktop-background-103791.jpg"]
];
$output = [];
foreach ($data as $row) {
$output[] = $row['file_name'];
}
echo implode(',', $output); // 3848765-wallpaper-images-download1.jpg,6941202-smile-desktop-background-103791.jpg