thinkphp使用select查询出的数据为二维数组,如果想将二维数组转一维,可以使用:

$x为二维数组对象
php版本要大于5.5.0
$userid_array = array_column($x,'userid');
php版本要大于5.4.0
$userid_array = array_map(function($item){return $item['userid'];},$x);

 dmeo:

public function index(){
		$roleInfo = M('role_user')->field('role_id')->where(['user_id' => 1])->select();
		if(version_compare(PHP_VERSION,'5.5.0','<')){
			die('php version need > 5.5.0');
		}else{
			//php版本要大于5.5.0
			$userid_array = array_column($roleInfo,'role_id');
			print_r($userid_array);
		}
    }

 

相关文章:

  • 2021-11-20
  • 2021-12-19
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-10-24
猜你喜欢
  • 2022-12-23
  • 2021-12-19
  • 2022-12-23
  • 2021-12-15
  • 2022-12-23
  • 2022-01-01
相关资源
相似解决方案