Jump to content

Need help in array


andz

Recommended Posts

i'm writing a code wherein it will parse more than 20 results from google trends depending on user specified input. i know this is just a basic problem, i already got the result but the problem i'm facing is that how do i loop it in order to display it properly to the user-end.

 

here's the array returned from that result...

 

Array

(

    [0] => jorge benvenuto

    [1] => usc ucla

    [2] => teleton usa

    [3] => ucla football

    [4] => school gyrls

    [5] => katia zatuliveter

    [6] => diddy dirty money

    [7] => ultimate fighter finale

    [8] => usc vs ucla 2010

    [9] => fiesta bowl

    [10] => dan henderson

    [11] => jonathan brookins

    [12] => saul alvarez

    [13] => kevin hart

    [14] => paul daley

    [15] => apple cup

    [16] => danner boots

    [17] => usc football

    [18] => teleton mexico

    [19] => strikeforce

)

 

Array

(

    [0] => amy railsback

    [1] => school gyrls

    [2] => apple cup

    [3] => winterfresh 2010

    [4] => apple cup score

    [5] => adrian gonzalez

    [6] => teleton usa

    [7] => bcs national championship

    [8] => apple cup 2010

    [9] => auburn vs south carolina

    [10] => usc vs ucla

    [11] => fiesta bowl

    [12] => jorge benvenuto

    [13] => usc ucla

    [14] => washington huskies football

    [15] => usc ucla football game 2010

    [16] => iliza shlesinger

    [17] => diddy dirty money

    [18] => danner boots

    [19] => lindsey buckingham

)

 

Array

(

    [0] => ventura show fema

    [1] => iliza shlesinger

    [2] => feminizing uranium

    [3] => ron santo

    [4] => cartoon pictures for facebook profile

    [5] => ron santo death

    [6] => naga viper

    [7] => uga admissions

    [8] => cartoon characters from the 80 s

    [9] => carlos slim

    [10] => pamela smart

    [11] => a walk in my shoes

    [12] => rosemary port

    [13] => uga

    [14] => matthew knight arena

    [15] => elaine kaufman

    [16] => parade of lights denver 2010

    [17] => cartoon characters from the 80s

    [18] => rugrats pictures

    [19] => 1970s cartoons

)

 

 

the length of the array depends on how many results the user want.s this one have 40 results but can be 100 or 60 or more than that.

 

thanks

 

 

Link to comment
https://forums.phpfreaks.com/topic/220727-need-help-in-array/
Share on other sites

Here's the full code to achieve that result.

 

 

/**

* Author: Andy Christian S. Loyola

* Created: Dec 1, 2010

*/

defined ('_IN_MAIN_MODULE') or die ('ACCESS DENIED');

 

class rendsAPI {

var $hourlyTrends = 'http://www.google.com/trends/hottrends/atom/hourly';

var $customTrends = 'http://www.google.com/trends/hottrends?sa=X&date=';

 

function curl($domain) {

$ch = curl_init($domain);

curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

$data = curl_exec($ch);

curl_close ($ch);

 

return $data;

}

 

function _parseTrends($data) {

preg_match_all('/.+?<a href=".+?">(.+?)<\/a>.+?/', $data, $matches);

return $matches[1];

}

 

function getSingleTrends() {

$data = $this->curl($this->hourlyTrends);

return $this->_parseTrends($data);

}

 

function getMultipleTrends($days = false) {

if ($days == false) {

return $this->getSingleTrends();

}

else {

$res = array();

 

$currentdate = strftime('%Y-%m-%d');

$start = 0;

 

for ($i = 0; $i < $days; $i++) {

$initstart = $start + 0;

 

$newdate = strtotime('-'.$initstart.' days', strtotime($currentdate));

$newdate = strftime('%Y-%m-%d', $newdate);

 

$start = $start + 1;

 

$res[] = $newdate;

}

 

$customTrends = array();

 

foreach ($res as $data) {

$custom = $this->curl($this->customTrends.$data);

$customTrends[] = $this->_parseTrends($custom);

}

 

return $customTrends;

}

}

}

 

 

I'm wondering if ican do a foreach() to that but to my current implementation of the foreach, it only return Array Array Array

Link to comment
https://forums.phpfreaks.com/topic/220727-need-help-in-array/#findComment-1143232
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.