我使用serialize方法将image_url和title和alt数据插入到MySQL数据库中,如下所示:
a:3:{i:0;a:4:{i:0;s:48:"uploads/media/galleries/nature/butterfly_001.jpg";i:1;s:43:"uploads/media/galleries/nature/IMG_4181.jpg";i:2;s:43:"uploads/media/galleries/nature/swan_002.jpg";i:3;s:45:"uploads/media/galleries/nature/zzmed copy.jpg";}i:1;a:4:{i:0;s:19:"test_title";i:1;s:20:"test_title1";i:2;s:25:"test_title2";i:3;s:24:"677777777777777777777777";}i:2;a:4:{i:0;s:19:"test_alt";i:1;s:21:"test_alt1";i:2;s:21:"test_alt2";i:3;s:26:"77888888888888888888888888";}}
PHP代码:
$value['gallery_data'] = serialize((array(array_values($_POST['image_url']), array_values($_POST['image_title']), array_values($_POST['image_alt']))));
现在,我可以像这样打印image_url:
$all1 = Access::fetch("SELECT * FROM " . GALLERIES . " WHERE id = ?", $id);
$array= unserialize($all1['0']['name']);
echo($array['0']['1']);
输出是:
uploads/media/galleries/nature/butterfly_001.jpg
但是,我需要为每个id打印列表所有image_url和image_title以及image_alt像这样:
uploads/media/galleries/nature/butterfly_001.jpg - test_title - test_alt
uploads/media/galleries/nature/IMG_4181.jpg - test_title1 - test_alt1
uploads/media/galleries/nature/zzmed copy.jpg - test_title2 - test_alt2
如何在foreach
方法中打印?!
答案 0 :(得分:0)
我的英语不好。所以,我把这段代码写给你。我希望这有用。
$un_arr = unserialize($arr);
$export = NULL;
array_walk_recursive($un_arr, function($val, $key) use (&$export ) {
$img_extension = array('.jpg','.jpeg');
foreach($extension as $value){
if(strpos($val,$value) != false){
$export .= $val . '<br>';
}
}
});
echo $export ;
如果这一行(strpos($ val,'。jpg')!= false)不起作用。你可以改成strpos($ val,'。jpg')!== false。我希望这能帮到你
我修复了许多扩展图像。希望这能帮到你