php - 取数组值并与其余部分分开
问题描述
我从 eloquent 查询并接收数组中的记录,我需要获取记录中团队的每个值,以验证它是大于还是小于表单中输入的值。
public function listarLojasParaValidarInsercaoHorarioLoja(string $uuidLoja,array $dados) : string
{
$loja = $this->getByLoja($uuidLoja);
$idLoja = $loja[0]->getLoja()->getId();
$diaSemana = $dados['dia_semana'];
$bancoHorario = HorarioLojaLaravel::where('loja_id', '=', $idLoja)
->where('dia_semana', '=', $diaSemana)->get();
$contarBanco = $bancoHorario->count();
if ($contarBanco > 0) {
$aberturaBanco = HorarioLojaLaravel::where('loja_id', '=', $idLoja)
->where('dia_semana', '=', $diaSemana)
->get('horario_abertura');
$fechamentoBanco = HorarioLojaLaravel::where('loja_id', '=', $idLoja)
->where('dia_semana', '=', $diaSemana)
->get('horario_fechamento');
foreach ($aberturaBanco as $key => $value) {
$horario_abertura = $dados['horario_abertura'];
$horario_fechamento = $dados['horario_fechamento'];
if ($horario_abertura >= $aberturaBanco and $horario_abertura <= $fechamentoBanco || $horario_fechamento <= $fechamentoBanco and $horario_fechamento >= $horario_abertura) {
echo $aberturaBanco;
} else {
echo $aberturaBanco;
}
}
} else {
return False;
}
}
结果 var_dump()
[{"horario_abertura":"08:00:00"},{"horario_abertura":"08:00:00"},{"horario_abertura":"08:00:00"},{"horario_abertura":"09:00:00"},{"horario_abertura":"09:00:00"}][{"horario_abertura":"08:00:00"},{"horario_abertura":"08:00:00"},{"horario_abertura":"08:00:00"},{"horario_abertura":"09:00:00"},{"horario_abertura":"09:00:00"}][{"horario_abertura":"08:00:00"},{"horario_abertura":"08:00:00"},{"horario_abertura":"08:00:00"},{"horario_abertura":"09:00:00"},{"horario_abertura":"09:00:00"}][{"horario_abertura":"08:00:00"},{"horario_abertura":"08:00:00"},{"horario_abertura":"08:00:00"},{"horario_abertura":"09:00:00"},{"horario_abertura":"09:00:00"}][{"horario_abertura":"08:00:00"},{"horario_abertura":"08:00:00"},{"horario_abertura":"08:00:00"},{"horario_abertura":"09:00:00"},{"horario_abertura":"09:00:00"}]
我需要得到数字
解决方案
我根据您的评论猜到您需要什么,替换->get('horario_abertura')
为->pluck('horario_abertura')
您的代码:
$aberturaBanco = HorarioLojaLaravel::where('loja_id', '=', $idLoja)
->where('dia_semana', '=', $diaSemana)
->pluck('horario_abertura');
并将您的 foreach 更改为:
foreach ($aberturaBanco as $key => $value) {
$horario_abertura = $dados['horario_abertura'];
$horario_fechamento = $dados['horario_fechamento'];
if ($horario_abertura >= $value and $horario_abertura <= $fechamentoBanco || $horario_fechamento <= $fechamentoBanco and $horario_fechamento >= $horario_abertura) {
echo $value;
} else {
echo $value;
}
}
另一个更简单的解决方案是什么都不做,用它$value['horario_abertura']
来获得你想要的值。
请告诉我它是否解决了您的问题。
推荐阅读
- javascript - 如何在选项标签中添加上标选择下拉列表 1st 2nd 3rd 4th 5th。1ST 我想要 S 大写字母,但我试过 s 将转换为小写
- html - 在Python中以某种形式的列表拆分HTML
- javascript - SWUP JS 外部函数调用
- java - AWS Java 开发工具包 SSL 证书
- css - Firebase 没有正确显示 CSS - 特别是媒体查询
- java - 如何按出现在文本图像中的顺序裁剪单词
- python - 将所有 .xls 转换为 .xlsx
- svg.js - 无法为 SVG.JS 中的函数创建的多边形设置动画
- python - urllib.request 在开头添加字符
- javascript - 登录失败时收到登录警报