小编Mat*_*son的帖子

PHP数组结合不起作用

公司阵列

array(1) { 
  [0]=> array(19) {
    ["entityid"]=> string(4) "3626" 
    ["entityparentid"]=> string(1) "0" 
    ["entityduplicateof"]=> string(1) "0" 
    ["entitytype"]=> string(1) "0" 
    ["entityname"]=> string(12) "Facebook Inc"
  } 
} 
Run Code Online (Sandbox Code Playgroud)

距离阵列

array(1) { 
  ["distance"]=> string(4) "1.22" 
} 
Run Code Online (Sandbox Code Playgroud)

我希望输出看起来像:

array(1) { 
    [0]=> array(19) {
        ["entityid"]=> string(4) "3626" 
        ["entityparentid"]=> string(1) "0" 
        ["entityduplicateof"]=> string(1) "0" 
        ["entitytype"]=> string(1) "0" 
        ["entityname"]=> string(12) "Facebook Inc" 
        ["distance"]=> string(4) "1.22" // here
    }
} 
Run Code Online (Sandbox Code Playgroud)

题:

array_push($company_array,$distance_array); 似乎没有做我想做的事.

它将它添加到最后,但不是我想要的地方(注意它放置的位置不同):

array(1) { 
    [0]=> array(19) {
      ["entityid"]=> string(4) "3626" 
      ["entityparentid"]=> string(1) "0" 
      ["entityduplicateof"]=> string(1) "0" 
      ["entitytype"]=> string(1) …
Run Code Online (Sandbox Code Playgroud)

php arrays

8
推荐指数
1
解决办法
37
查看次数

Trello API:在一次通话中获取会员,附件和卡信息?

我可以使用以下方法从Trello API获取数据:

private function get_card_info($card_id) {
    $client =         new \GuzzleHttp\Client();
    $base =           $this->endpoint . $card_id;
    $params =         "?key=" . $this->api_key . "&token=" . $this->token;      
    $cardURL =        $base . $params;
    $membersURL =     $base . "/members" . $params;
    $attachmentsURL = $base . "/attachments" . $params;

    $response = $client->get($cardURL);
    $this->card_info['card'] = json_decode($response->getBody()->getContents());

    $response = $client->get($membersURL);
    $this->card_info['members'] = json_decode($response->getBody()->getContents());

    $response = $client->get($attachmentsURL);      
    $this->card_info['attachments'] = json_decode($response->getBody()->getContents());
}
Run Code Online (Sandbox Code Playgroud)

但是,这分为三个电话.有没有办法在一次通话中获取卡信息,会员信息和附件信息?该文件提到使用&fields=name,id,但似乎只来限制从基础调用返回的真实cards端点.

每次我需要卡片信息时都必须打3次API是荒谬的,但我找不到任何收集所有需要的例子.

php trello

6
推荐指数
2
解决办法
1113
查看次数

为什么我的mongo容器的docker-compose健康检查总是失败?

docker-compose用来站一个Express / React / Mongo应用程序。目前,我可以使用Express应用程序中的重试逻辑来支持一切。但是,我更喜欢使用Docker的healthcheck来防止容器最初启动时出现错误字符串。但是,当我在中添加a healthcheckdocker-compose.yml,它将挂起间隔/重试时间限制,并退出:

ERROR: for collector  Container "70e7aae49c64" is unhealthy.

ERROR: for server  Container "70e7aae49c64" is unhealthy.
ERROR: Encountered errors while bringing up the project.
Run Code Online (Sandbox Code Playgroud)

看来我的健康检查从未恢复健康状态,我也不完全知道为什么。我的整个docker-compose.yml

version: "2.1"
services:
  mongo:
    image: mongo
    volumes:
      - ./data/mongodb/db:/data/db
    ports:
      - "${DB_PORT}:${DB_PORT}"
    healthcheck:
      test: echo 'db.runCommand("ping").ok' | mongo mongo:27017/test --quiet 1
      interval: 10s
      timeout: 10s
      retries: 5
  collector:
    build: ./collector/
    environment:
      - DB_HOST=${DB_HOST}
      - DB_PORT=${DB_PORT}
      - DB_NAME=${DB_NAME}
    volumes:
      - ./collector/:/app
    depends_on:
      mongo: …
Run Code Online (Sandbox Code Playgroud)

mongodb docker docker-compose

4
推荐指数
4
解决办法
3558
查看次数

你如何在 Laravel 的 json 响应中返回一个视图?

我正在使用 Laravel 实现一个简单的注册表单。失败时,它应该返回一个 json 响应:

{"success":"false", "message":"Could not log in newly registered user"}`
Run Code Online (Sandbox Code Playgroud)

这按预期工作。如果注册和登录成功,我想返回:

{"success":"true", "message":$html}
Run Code Online (Sandbox Code Playgroud)

在这种情况下,$html将使用视图创建。这其中的重要部分如下:

if(Auth::attempt(array('email' => Input::get('email'), 'password' => Input::get('password'))))
{
    $html = View::make('welcome_new_user', array('first_name' => Input::get('first_name')));
    return Response::json(array('success' => 'true', 'message' => $html));
}
else
{
    return Response::json(array('success' => 'false', 'message' => 'Could not log in newly created user.'));
}
Run Code Online (Sandbox Code Playgroud)

失败时,我得到预期的响应。成功后,我得到"success":"true",但是一个空的message. 我$html在返回之前立即回显了,它包含预期的 html。为什么返回的消息是空的?

php json laravel laravel-4

2
推荐指数
1
解决办法
3383
查看次数

逐个像素地改变图像的颜色

我试图改变png图像的颜色,使透明区域仍保持透明,并为图像的其余部分添加颜色,这就是我试过的

<?php

$im = imagecreatefrompng('2.png');
$w = imagesx($im);
$h = imagesy($im);

$om = imagecreatetruecolor($w,$h);

for ($x = 0; $x < $w; $x++) {
    for ($y = 0; $y < $h; $y++) {
        $rgb = imagecolorat($im, $x, $y);
        $colors = imagecolorsforindex($im,  $rgb);

        $orgb = imagecolorallocate($om,$colors['alpha'],$colors['alpha'],$colors['alpha']);
        imagesetpixel($om,$x,$y,$orgb);
    }
}

header('Content-Type: image/png');
imagepng($om);

imagedestroy($om);
imagedestroy($im);

?>   
Run Code Online (Sandbox Code Playgroud)

它产生的图像如下: 之前

在此输入图像描述

在此输入图像描述

我仍然没有准确的想法如何获得png图像的突出显示区域并给它们一种颜色,如黄色或粉红色而不会失去透明度,这样只有非透明区域才能保持透明

php gd image-processing

1
推荐指数
1
解决办法
5179
查看次数