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');
});
gettype returns the type of the variable as a string result and that result might be "array", but it's still a string. So the dd / var_dump shows it as a string. Try:
echo gettype($default);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With