エラーメッセージ
array_flip(): Can only flip string and integer values, entry skipped
//文字列と整数値のみを反転できます。入力はスキップされます
問題のコード
.php
$allCookie = $request->cookie();
$allCookie = array_flip($allCookie);
原因
array_flip()
は配列(連想配列)のキーとバリューを入れ替えるメソッド。
array_flip()
は文字列と整数値のみしか扱えない。
$request->cookie()
でcookieを取得したが、内容は下記でNULL値
が存在したためエラーとなった。
^ array:4 [▼
"ABC_asdfpipoij3" => null
"CLA_sdfgsg" => null
"XSRF-TOKEN" => "RRY2bgJ1h2onOYmsdfgsdfSmTVa2OrdrNNBaXYDsg8PnBOp"
"session" => "6r2FazkYws4asdrIeStTuBzasdfoHLj9wjqciNPtToYYo2D"
]
対処法
array_filter
でNULL
を取り除く
.php
$allCookie = $request->cookie();
$allCookie = array_filter($allCookie, function ($value) { return $value !== null; });
$allCookie = array_flip($allCookie);
参照