SET DATEFORMAT dmy;
SELECT DATENAME(dw,CAST('02-08-2018' AS date)) AS day
这是我正在调试的代码部分。 gettype确认$ Garrr是一个字符串。但是,我仍然收到非法偏移类型错误。我一辈子都找不到原因,尽管我不愿意将其发布在网上,但我确实已经呆了太久了。任何帮助将不胜感激。
答案 0 :(得分:2)
您不需要构建自己的ucword。
Ucwords创建了所谓的驼峰式大小写,将句子中的每个单词都大写。
不确定$ ReasonNumbers是否在其他地方创建,但是如果要使用array_merge,它是否必须存在。
并且array_merge返回数组,因此需要=
。
[$ Garr]应该是$ Garr。
$ReasonNumbers = [];
$m = "reason here:@:0";
$c = explode(":@:",$m);
$Garrr = ucwords($c[0]);
$Huff = array($Garrr => $c[1]);
//echo gettype($Garrr);
$ReasonNumbers = array_merge($ReasonNumbers,$Huff);
Var_dump($ReasonNumbers);
输出:
array(1) {
["Reason Here"]=>
string(1) "0"
}
答案 1 :(得分:0)
“非法偏移类型”错误与数组索引的错误使用有关,例如,使用 Object 类型而不是数字或纯字符串。
$array = array("a", "b", "c");
$obj = new stdClass();
$value = $array[$obj]; // this doesn't work
因此,您需要使用对象作为索引来检查行。
使用gettype
($ var),您可以检查返回的值是否是对象[http://php.net/manual/en/function.gettype.php]
如果$ Garr
是一个对象,则需要使用另一种类型的索引,例如,使用spl_object_hash
[http://php.net/manual/en/function.spl-object-hash.php]