Php 7.4 xampp Trying to access array offset on value of type null
I m working with lravel 7 project before i used to work with xampp 7.3.21 / PHP 7.3.21
and everything is so good ive upgraded to xampp 7.4.9 / PHP 7.4.9
and i get
Trying to access array offset on value of type null
in the most of my porject and this is example
public function show
(
$id,
// selects
$selects_names,
$selects_languages,
$selects_models,
$selects_policies,
$selects_types,
$selects_ranks,
// end selects
)
{
return view('curd.show',compact
(
'id'
// select
'selects_names',
'selects_languages',
'selects_models',
'selects_policies',
'selects_types',
'selects_ranks',
// end selects
));
}
and this is the blade code
@if($selects_names)
@foreach($selects_names as $key => $selects_name)
@include(
'treats.show_selects',
[
'name' => $selects_name,
'language' => $selects_languages[$key],
'model' => $selects_models[$key],
'policy' => $selects_policies[$key] ?? null,
'show_type' => $selects_types[$key],
'rank' => $selects_ranks[$key] ?? null,
]
)
@endforeach
@endif
and always get the above error most of my program is included from the code above they are treate function and now most of it now working
1 Answer
Some key in $select_names
is probably not in the other arrays. Define a default value for the other arrays as you did for $select_policies
and $select_ranks
:
[
'name' => $selects_name,
'language' => $selects_languages[$key] ?? '',
'model' => $selects_models[$key] ?? null,
'policy' => $selects_policies[$key] ?? null,
'show_type' => $selects_types[$key] ?? null,
'rank' => $selects_ranks[$key] ?? null,
]