我今天有一个相当简单的问题。我们有以下资源:
$a = array(1 => 5, 2 => 3, 3 => 13, 9 => array('test'), 4 => 32, 5 => 33);
Run Code Online (Sandbox Code Playgroud)
实际上如何才能找出数组“a”中是否有数组元素并在有一个(或多个)时返回键?
我现在有2张桌子,它们看起来如下:
该points表如下所示:
id country points
1 4 1
2 7 5
3 8 4
Run Code Online (Sandbox Code Playgroud)
该sample表如下所示:
id iso pts
1 UK 100
2 US 300
3 AU 700
4 BO 1200
5 BA 1500
6 BR 2000
7 HR 5000
8 TD 10000
9 CA 15000
Run Code Online (Sandbox Code Playgroud)
我基本上想要的是从points表中选择所有数据,points.country并且points.points对应于sample.iso和sample.pts.
所以我想要达到的结果是:
id country points
1 BO 100
2 HR 1500
3 TD 1200
Run Code Online (Sandbox Code Playgroud)
这实际上是否可以实现?如果有,怎么样?
我有一个用于创建会话的简单文件,它类似于以下内容:
<?php namespace App\Repositories\Managers;
use Illuminate\Support\Facades\Session;
use Carbon\Carbon;
class SessionTest {
public function __construct()
{
}
public function sessionTest()
{
Session::put('test', 111);
dd(Session::all());
}
}
Run Code Online (Sandbox Code Playgroud)
它使我的会议符合预期。
array:4 [?
"_token" => "pYbrTbhnsLx6BfUNZusedQSYiBGxL3t9W7IyRVAh"
"_previous" => array:1 [?]
"flash" => array:2 [?
"old" => []
"new" => []
]
"test" => 111
]
Run Code Online (Sandbox Code Playgroud)
现在由于某种原因,当我打开另一个页面并显示Session :: all()时,它带给我以下内容:
array:3 [?
"_token" => "pYbrTbhnsLx6BfUNZusedQSYiBGxL3t9W7IyRVAh"
"_previous" => array:1 [?]
"flash" => array:2 [?
"old" => []
"new" => []
]
]
Run Code Online (Sandbox Code Playgroud)
基本上,一旦打开新页面,它将删除所有会话存储。
我的session.php文件如下所示:
<?php
return …Run Code Online (Sandbox Code Playgroud) 使用 Laravel 7.6 及其内置的 HTTP 客户端。
body我正在尝试将原始 JSON 格式的简单 POST 请求发送到我的其他域,但没有成功:
$response = Http::post('https://example.com', [
'body' => '{ test: 1 }'
]);
Run Code Online (Sandbox Code Playgroud)
我收到 400 Bad Request - 客户端错误 - 因为我的服务器期望body这是强制性的。
我在这里缺少什么?
我想检索一个图表的数据,我想为它提出一个简单的解决方案,而不是做8个子查询.
这就是users表格的样子:
user_id
1
2
3
4
5
Run Code Online (Sandbox Code Playgroud)
这就是pts表格的样子:
id user_id status points time
1 1 0 100 2014-08-23 03:34:54
2 4 0 100 2014-08-23 04:04:44
3 1 1 300 2014-08-23 08:34:21
4 1 0 300 2014-08-23 15:25:11
5 1 0 200 2014-08-23 22:23:12
Run Code Online (Sandbox Code Playgroud)
查询看起来像这样(带有一些注释,我不知道要放什么):
"SELECT *,
(
SELECT SUM(points)
FROM pts
WHERE status = 0
AND user_id = 1
AND time >= "THIS DAY'S 00:00" AND <= "THIS DAY'S 03:00"
),
(
SELECT SUM(points)
FROM …Run Code Online (Sandbox Code Playgroud) 当我尝试为子查询提供别名,然后在 Where 子句中引用它时,我收到一条错误消息:“where 子句”中的未知列“point_status”
SELECT goals.id, goals.status,
ifnull((SELECT point_status FROM pts WHERE point_id = ?), goals.status) as point_status
FROM goals
WHERE goals.name = ? AND point_status > 1
Run Code Online (Sandbox Code Playgroud)
我不明白为什么它不允许我使用这个别名。通过不修改查询的功能,是否可以在 where 子句中以某种方式使用该别名?
我已经阅读了很多文章,并在寻找用于检测移动设备的解决方案。实际上遇到了https://github.com/serbanghita/mobile-detect,但这是一个相当庞大的php类。
我实际上想要一个非常简单的解决方案。我想确定用户的浏览器是Mobile / iPad / etc还是Desktop。所以我想要这样的事情:
<?php
require('detector.php');
if(isMobile() === true)
{
header('mobile.php');
exit();
}
else
{
header('desktop.php');
exit();
}
Run Code Online (Sandbox Code Playgroud)
?>
需要一个非常简单的解决方案,无需安装composer或任何php框架即可将其放置在任何页面上。
实际上这怎么可能?
我正在使用 Laravel 6 和 Eloquent。我正在寻找一种方法来更新一组具有设定值的行,每个行都用唯一的 ID 进行标识。
这就是我现在正在做的事情:
$ids = [3948, 1984, 7849, 4456, 394];
$value = false;
foreach ($ids as $id)
{
User::where("id", $id)->update(["status" => $value]);
}
Run Code Online (Sandbox Code Playgroud)
有没有办法只用 1 个查询而不是 5 个查询来完成相同的任务?
我从 API 调用收到一个对象。我想检查:
假设我期待以下对象:
success.response.data.users.items.list
Run Code Online (Sandbox Code Playgroud)
现在我想知道这个list对象是否存在。
我试过了:
typeof success.response.data.users.items.list !== "undefined"
我得到的错误: TypeError: Cannot read property 'data' of undefined
success.hasOwnProperty("response.data.users.items.list")
这始终评估为 false,因为 hasOwnProperty 显然无法检查多级对象。
success.response.data.users.items.hasOwnProperty("list")
我得到的错误: TypeError: Cannot read property 'data' of undefined
有没有任何现代和快速的方法来检查这个?
我有一个按钮,我想要一个稍微透明的覆盖层,以便在悬停时“滑过”按钮。
有一种叫做“涟漪效应”的东西,您通常可以通过单击按钮来实现。
像这里:https : //codepen.io/tomma5o/pen/zwyKya
HTML:
<div class="container">
<a data-animation="ripple">Click Me</a>
</div>
Run Code Online (Sandbox Code Playgroud)
CSS:
:root {
/* if u want to change the color of
* the ripple change this value
*/
--color-ripple: rgba(255,255,255,0.8);
}
body {
background: #36353c;
}
.container {
position: absolute;
top: 0;
left: 0;
right: 0;
bottom: 0;
height: 50px;
width: 200px;
margin: auto;
}
*[data-animation="ripple"] {
position: relative; /*Position relative is required*/
height: 100%;
width: 100%;
display: block;
outline: none;:root {
/* if u want …Run Code Online (Sandbox Code Playgroud)