I have the following code
dd(gettype($default));
$test = substr($default,0,2);
gettype returns that the type of $default is string The following error happens on the second line:
substr() expects parameter 1 to be string, array given
How is this happening, and how can I solve it?
edit var_dump also returns a string as type
edit $default contains the following string: "1015"
edit complete code block
Form::macro('time', function ($name, $default) {
$hours = value(function () use ($default){
echo gettype($default);
$test = substr($default,0,2);
$hours = ['' => $test];
for ($hour = 0; $hour < 24; $hour++) {
$hours[$hour] = $hour;
}
return $hours;
});
edit code where the macro is used
{{ Form::label('reservation_starthour', 'starthour') }}
{{ Form::time('starthour',$reservation->starthour) }}
Schema of the reservation table
Schema::create('reservations', function (Blueprint $table) {
$table->increments('id');
$table->integer('group_id')->unsigned();
$table->date('startdate');
$table->date('enddate');
$table->string('starthour');
$table->string('endhour');
});
dd($default)without thegettypewhat does it return?dd(gettype($default));var_dump($default);$test = substr($default,0,2);If var_dump will be array then it means that the problem is in dd()dd(). That function doesn't modify anything.