我有以下代码PHP识别字符串作为阵列
dd(gettype($default));
$test = substr($default,0,2);
的GetType返回该的$默认类型是串 在第二行上发生以下错误:
substr() expects parameter 1 to be string, array given
这是怎么发生的,我该如何解决?
编辑的var_dump也返回一个字符串类型
编辑 $默认包含下列字符串: “1015”
编辑完整码块
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;
});
编辑使用宏的代码
{{ Form::label('reservation_starthour', 'starthour') }}
{{ Form::time('starthour',$reservation->starthour) }}
预约表
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()是什么? – VeeeneX 2015-02-11 20:46:37
@VeeeneX这是一个内置的Laravel函数:var_dump和die,dd。如果'dd($ default)'没有'gettype',它会返回什么? – 2015-02-11 20:47:08
做一些基本的故障排除,Var转储所有变量以查看它们的价值 – Patrick 2015-02-11 20:47:12