把数组转化为字符串和字符串再转化成数组

1、//把数组转化为字符串并用@链接起来
$str ='';
foreach ($goodshop as $k => $v) {
    $v=json_decode($v,true);
    //php中字符串连接是用.连接的
    $str = $str.$v['goodshop']."@";
}
//去除最后一个字符
$newstr = substr($str,0,strlen($str)-1); 
2、//将字符串转换为数组
$doGoods=session('newstr');
$goodsdel = explode("@", $doGoods);
//tp5中批量删除数据
$data=db('cart')->where('user_id',$uid)->where('goodshop','in',$goodsdel)->delete();

猜你喜欢

转载自blog.csdn.net/fzxyxf1314/article/details/89400631