PHP警告Cannot use a scalar value as an array
2017-02-17 13:52
621 查看
报错代码
更正代码:
foreach ($data as $key => $value) { $strtotime = strtotime($key) + 3600 * 8; $time = intval($strtotime / 86400); try { $cache = Yii::$app->cache->instance('base'); foreach ($channels as $key1 => $value1) { $k = "user:state:USER_V_O#".$value1."#"; $set = $cache->exists($k . $time); if (!$set) { $data[$key][$value1] = 0; } else { $nums = $cache->scard($k . $time); $data[$key][$value1][]=intval($nums); } } } catch (Exception $ex) { //TODO待做 $error = '获取数据库信息失败'; } }
更正代码:
foreach ($data as $key => $value) { $strtotime = strtotime($key) + 3600 * 8; $time = intval($strtotime / 86400); /****处理报错****/ if (!$data[$key]) { $data[$key]= []; } /****结束****/ try { $cache = Yii::$app->cache->instance('base'); foreach ($channels as $key1 => $value1) { $k = "user:state:USER_V_O#".$value1."#"; $set = $cache->exists($k . $time); if (!$set) { $data[$key][$value1] = 0; } else { $nums = $cache->scard($k . $time); $data[$key][$value1][]=intval($nums); } } } catch (Exception $ex) { //TODO待做 $error = '获取数据库信息失败'; } }
相关文章推荐
- PHP警告Cannot use a scalar value as an array的解决方法
- PHP警告Cannot use a scalar value as an array的解决方法
- php下关于Cannot use a scalar value as an array的解决办法
- php下关于Cannot use a scalar value as an array的解决办法
- php下关于Cannot use a scalar value as an array的解决办法
- 关于Cannot use a scalar value as an array的解决办法
- 关于Cannot use a scalar value as an array的解决办法
- Cannot use a scalar value as an array?
- PHP中遍历stdclass object 报错Fatal error: Cannot use objectof type stdClass as array
- PHP错误Cannot use object of type stdClass as array in错误的解决办法
- PHP“Cannot use object of type stdClass as array”
- php “Cannot use object of type stdClass as array” 的解决方法
- PHP JSON出错:Cannot use object of type stdClass as array解决方法
- Cannot use object of type PHPExcel_RichText as array
- php错误 Fatal error: Cannot use object of type stdClass as array in……
- PHP 错误:Cannot use object of type yii\db\Command as array
- PHP“Cannot use object of type stdClass as array” (php在调用json_decode从字符串对象生成json对象时的报错)
- PHP“Cannot use object of type stdClass as array”
- PHP“Cannot use object of type stdClass as array”
- PHP“Cannot use object of type stdClass as array”