0

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)

0

2 Answers 2

1

If i understand you,

If you change your html form code like this:

<input type="text" name="competitorUrl[1]" style="width:350px; border-radius:3px;">
<input type="text" name="competitorUrl[2]" style="width:350px; border-radius:3px;">
<input type="text" name="competitorUrl[3]" style="width:350px; border-radius:3px;">

You can get your data array format, example:

$competitorUrls = $request->get('competitorUrl');
foreach($competitorUrls as $url)
{
     // Your codes for every url
}

And when you need add a something variable and key;

$competitorUrls["yourkey"] = "your value";

Good luck.

Sign up to request clarification or add additional context in comments.

Comments

0

May be the $params is empty in line

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

2 Comments

But it should be displayed as null in array tho', right?
hm at the end of your question you show some array - but this array is not $nice_array

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.