0

I am currently working with the lat.fm api to develop an app.

I have a function which runs to pull in the weekly track listing from a last.fm group.

The aim is to pull in the album artwork and to make a "gridview" template.

The below code does this:

public function getWeeklyTrackChartGrid($methodVars) {
        // Check for required variables
        if ( !empty($methodVars['group']) ) {
            $vars = array(
                'method' => 'group.getweeklytrackchart',
                'api_key' => $this->auth->apiKey
            );
            $vars = array_merge($vars, $methodVars);

            if ( $call = $this->apiGetCall($vars) ) {
                $i = 0;


                //shuffle($call->weeklytrackchart->track);

                $loopN = $call->weeklytrackchart->track;


                foreach ($loopN as $track ) {

                    require 'config.php';
                     //if(++$i > $userLimit*2) break;


                     $albumArtS = $tracks['album']['image']['small'] = (string) $track->image[0];
                     $albumArtM = $tracks['album']['image']['small'] = (string) $track->image[1];
                     $albumArtL = $tracks['album']['image']['small'] = (string) $track->image[2];

                     $playCounts = $tracks[$i]['playcount'] = (string) $track->playcount; 

                     ?>


                       <?php if ($playCounts > 1)  { ?>

                       <?php if ($albumArtL)  { ?>

                            <img src="<?php echo $albumArtL; ?>" />

                            <?php } ?>

                       <?php } else { ?>

                       <?php if ($albumArtM)  { ?> 

                            <img src="<?php echo $albumArtM; ?>" />

                            <?php } ?>

                       <?php } ?>



                     <?php if ($albumArtwork == "yes")  { ?>


                        <?php if ($albumArt)  { ?>




                        <?php } }?>



                <?php   $i++;
                }
                return $tracks;
            }
            else {
                return FALSE;
            }
        }
        else {
            // Give a 91 error if incorrect variables are used
            $this->handleError(91, 'You must include a group variable in the call for this method');
            return FALSE;
        }
    }

I would like to use the php function shuffle on the foreach loop to randomise the tracks, rather than pull them in, in the order last.fm gives them you.

As you can see i havent commented the shuffle function out above, as when i add this i get the following warning:

Warning: shuffle() expects parameter 1 to be array, object given in 

Any ideas on what could be the problem?

Cheers, Dan

danyo
  • 5,686
  • 20
  • 59
  • 119

1 Answers1

0
$loopN = (array) $call->weeklytrackchart->track;
shuffle($loopN);
蒋艾伦
  • 464
  • 1
  • 5
  • 16