Laravel convert an array into a string and then convert the string to a group

Source: Internet
Author: User
Tags explode

This is the way to change the code for Nanshao, the beginning of the data with the explored conversion group is not the result, I wrote a method to extract the useful information into a string, and then use explored to convert the string into a group. The method is a bit stupid, but finally solves the problem of Nanshao

$re 1= db::table (' Admin_user ')            -Join(' Admin_role_user ', ' admin_user.id ', ' = ', ' admin_role_user.user_id ')                ->select (' admin_role_user.role_id ', ' admin_user.username ')                ->where (' Admin_user.id ',$user-ID)-get ();//DD ($re 1);//The direct conversion of the array is not the desired result//DD (Explode (', ', $re 1));//This is converting it to a string            $str= ""; $cnt= 0; foreach($re 1  as $value)            {                if($cnt= = 0) {                    $str=$value-role_id; }                Else{                    $str=$str.‘,‘.$value-role_id; }                $cnt++; }//DD ($STR);//Here Use explode (', ') to turn the string into a group/DD (Explode (', ', $str));

Laravel convert an array into a string and then convert the string to a group

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.