array_flip(): Can only flip string and integer values, entry skipped in Laravel

Updated at 26-Aug-2022, By samar

array_flip(): Can only flip string and integer values, entry skipped in Laravel

In this session, we are going to try to solve the "array_flip(): Can only flip string and integer values, entry skipped in Laravel" puzzle by using the computer language.

Getting error `array_flip(): Can only flip string and integer values, entry skipped` while using flip method on collection in Laravel.
$collection = collect([
    ['website' => 'twitter'],
    ['url' => 'twitter.com']
]);
  • Change array collection format

    $collection = collect(
    	['website' => 'twitter', 'url' => 'twitter.com']
    );
    
    $flipped = $collection->flip();
    $flipped->all();
    print_r($flipped);
    

    Output

    Illuminate\Support\Collection Object ( [items:protected] => Array ( [twitter] => website [twitter.com] => url ) [escapeWhenCastingToString:protected] => )

Back to code snippet queries related laravel