dongwenghe2416 2016-08-02 20:56
浏览 91

在动态数组中添加元素

I have four inputs:

<form id="query" method="POST">
<input type="text" name="mainUrl" style="width:350px; border-radius:3px;">
<input type="text" name="competitorUrl1" style="width:350px; border-radius:3px;">
<input type="text" name="competitorUrl2" style="width:350px; border-radius:3px;" >
<input type="text" name="competitorUrl3" style="width:350px; border-radius:3px;">
</form>

I return the inputs like this:

public function getAlexaAverageRankData($params){
        $return = [];
        if (!empty($params["mainUrl"])){
            $return["mainUrl"] = $this->getAverageRank($params["mainUrl"]);
        }
        if (!empty($params["competitorUrl1"])){
            $return["competitorUrl1"] = $this->getAverageRank($params["competitorUrl1"]);
        }
        if (!empty($params["competitorUrl2"])){
            $return["competitorUrl2"] = $this->getAverageRank($params["competitorUrl2"]);
        }
        if (!empty($params["competitorUrl3"])){
            $return["competitorUrl3"] = $this->getAverageRank($params["competitorUrl3"]);
        }
        return $return;
    }

Where params are the following parameters:

protected function buildQueryParams($site) {
    $params = array(
        'Action'            => self::$ActionName,
        'ResponseGroup'     => self::$ResponseGroupName,
        'AWSAccessKeyId'    => $this->accessKeyId,
        'Timestamp'         => self::getTimestamp(),
        'Count'             => self::$NumReturn,
        'Start'             => self::$StartNum,
        'SignatureVersion'  => self::$SigVersion,
        'SignatureMethod'   => self::$HashAlgorithm,
        'Url'               => $site
    );
    ksort($params);
    $keyvalue = array();
    foreach($params as $k => $v) {
        $keyvalue[] = $k . '=' . rawurlencode($v);
    }
    return implode('&',$keyvalue);
}

And this is the array I am returning:

$nice_array = array(
            'Rank'           => $info->TrafficData->Rank,
            'Links In Count' => $info->ContentData->LinksInCount,
            'Site'           => $info->getAlexaAverageRankData($params),
        );
        return $nice_array;

The problem is that my array only contains Rank and Links In Count right now. I need to also have an entry in the array for every url the user has put in that input. The method I am using to return the url's is working but I need to echo them into nice_array. How can I do that? I am sorry if some things are unclear, trust me they are unclear to me as well...I am a beginner and I don't know how to solve this problem. My array structure looks like this right now:

 ["data"]=>
  object(stdClass)#227 (2) {
    ["mainUrl"]=>
    object(stdClass)#233 (2) {
      ["Rank"]=>
      object(stdClass)#236 (1) {
        ["0"]=>
        string(8) "20231208"
      }
      ["Links In Count"]=>
      object(stdClass)#235 (0) {
      }
    }
    ["competitorUrl1"]=>
    object(stdClass)#239 (2) {
      ["Rank"]=>
      object(stdClass)#240 (1) {
        ["0"]=>
        string(5) "24971"
      }
      ["Links In Count"]=>
      object(stdClass)#241 (1) {
        ["0"]=>
        string(3) "640"
      }
    }
  }

If there is something unclear ask me and I will try to explain it to you...I am sorry for this ambiguous question, I am doing my best to make things clear. Thank you for your time and help. (more info here: https://gist.github.com/michaelwowro/4130431)

  • 写回答

2条回答 默认 最新

  • dorflv5944 2016-08-02 21:39
    关注

    May be the $params is empty in line

    'Site'           => $info->getAlexaAverageRankData($params),
    
    评论

报告相同问题?

悬赏问题

  • ¥15 RPA正常跑,cmd输入cookies跑不出来
  • ¥15 求帮我调试一下freefem代码
  • ¥15 matlab代码解决,怎么运行
  • ¥15 R语言Rstudio突然无法启动
  • ¥15 关于#matlab#的问题:提取2个图像的变量作为另外一个图像像元的移动量,计算新的位置创建新的图像并提取第二个图像的变量到新的图像
  • ¥15 改算法,照着压缩包里边,参考其他代码封装的格式 写到main函数里
  • ¥15 用windows做服务的同志有吗
  • ¥60 求一个简单的网页(标签-安全|关键词-上传)
  • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。