Happy Laracon Week! All accounts are 60% off this week.

Shawdow's avatar

Array to string and String to Array in laravel??

Since I am new to Laravel little confused about array to string and string to array conversion Can I Covert below examples as i asked??

1.How to convert below variable $user->post string value to an Array?

 $user->post = Input::get("description");

2.How to convert below $data array value string??

$data = DB::table('posts')->select('titile')->get();

Thanks

0 likes
1 reply
Shawdow's avatar

@flackovic

thanks for the reply!!

This is what i am trying to do as below!!

I have tried above solution!!

I am trying check the if condition either true or false with variable $data but the variable $data is in array format and $user->post is in string format

How can i make both variable with same type match with if condition


 $user->post = Input::get("description");

$data = DB::table('posts')->select('title')->get()->toArray();
        
foreach($data as $t) {
            
            
            if($user->post == $t){
                    

               //some code...

           }
}

Please or to participate in this conversation.