找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
热搜: 活动 拇指 mztk
查看: 1844|回复: 1

PHP explode分割字符串

[复制链接]

134

主题

52

回帖

4913

积分

版主

积分
4913
发表于 2022-4-10 15:29:31 | 显示全部楼层 |阅读模式
PHP explode分割字符串,字符串拆分

mysql数据表字段:jiguan=1,1,1,1,1

$cha['jg'] = "";
$bjid = Cookie::get('bjid');
$cha =  $rows = RenyuanModel::alias('a')
    ->join('kehu b', 'a.kid = b.id')
    ->join('bumen c', 'a.bid = c.bmid')
    ->where(['a.rycd' =>1,'ryid' => $bjid])
    ->field('a.*,b.id,b.knames,c.bmid,c.bmname')
    ->find();
/*籍贯部分开始*/
//查询出籍贯,分割字符串
$jiguans = $cha['jiguan'];
$sheng = explode(',',$jiguans)[0];
$shi = explode(',',$jiguans)[1];
$xian = explode(',',$jiguans)[2];
$zhen = explode(',',$jiguans)[3];
$cun = explode(',',$jiguans)[4];
$chasheng = Db::table('dzsheng')->where('id',$sheng)->find();
$chashi = Db::table('dzshi')->where('id',$shi)->find();
$chaxian = Db::table('dzxian')->where('id',$xian)->find();
$chazhen = Db::table('dzzhen')->where('id',$zhen)->find();
$chacun = Db::table('dzcun')->where('id',$cun)->find();
$gang = '-';
$cha['jg'] = $chasheng['shname'].$gang.$chashi['sname'].$gang.$chaxian['xname'].$gang.$chazhen['zname'].$gang.$chacun['cname'].$gang.$cha['jiguanz'];
/*籍贯部分结束*/
$data = [
    'code' => 200,
    'rows' => $cha
];
return json($data);
回复

使用道具 举报

134

主题

52

回帖

4913

积分

版主

积分
4913
 楼主| 发表于 2022-4-10 15:31:17 | 显示全部楼层
如果全部查询$sheng = explode(',',$jiguans);
只查询前3个$sheng = explode(',',$jiguans,2);
指定查询第几个$sheng = explode(',',$jiguans)[3];

explode是从0开始算第一个
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|手机版|再加计算机 ( 鲁ICP备19060125号-10|鲁公网安备37028102001711号 )

GMT+8, 2026-9-11 19:54 , Processed in 0.094026 second(s), 23 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2026 Discuz! Team.

快速回复 返回顶部 返回列表