cgm225 Posted May 29, 2008 Share Posted May 29, 2008 I have a two dimensional array with multiple entries, something created like: $this->Data[$id] = array( 'dir' => $dir, 'filename' => $filename ); And then I find a particular key and value in that array like so: return $this->Data[$this->id]; However, how can I reset the $this->Data array to hold just the $this->Data[$this->id] value, and none of the other values that were also in the array, and also still maintaining the two dimensional structure. Quote Link to comment Share on other sites More sharing options...
rhodesa Posted May 29, 2008 Share Posted May 29, 2008 hum...interesting...how about: $this->Data = array( $this->id => $this->Data[$this->id] ); Quote Link to comment Share on other sites More sharing options...
cgm225 Posted May 29, 2008 Author Share Posted May 29, 2008 Well, here is my overall problem, I have a class with two methods, findAlbums and findAlbum, and I need both to return the data in the same "format" so they can be outputted the same way. Any ideas? I have commented where my problem is: public function findAlbums() { /* Queries database and creates a two dimensional array of all albums * and each album's associated data. */ $query = 'SELECT id, full_title, short_title, dir, timestamp FROM albums ORDER BY timestamp DESC'; $statement = $this->connection->prepare($query); $statement->bind_result($id, $fullTitle, $shortTitle, $dir, $timestamp); $statement->execute(); while($statement->fetch()) { $this->albumData[$dir] = array( 'id' => $id, 'fullTitle' => $fullTitle, 'shortTitle' => $shortTitle, 'dir' => $dir, 'timestamp' => $timestamp ); } /* If a dirctory name has been provided via a GET variable, then only * the album corresponding to that directory name will be returned in the * array. */ if(isset($this->dir)) { $this->findAlbum(); } else { return $this->albumData; } } public function findAlbum() { //Returns a specific album and its associated data return $this->albumData[$this->dir]; //PROBLEM AREA; THIS NEEDS TO BE SOMETHING ELSE?? } Quote Link to comment Share on other sites More sharing options...
cgm225 Posted May 29, 2008 Author Share Posted May 29, 2008 Using: public function findAlbum() { //Returns a specific album and its associated data $this->albumData = array($this->dir => $this->albumData[$this->dir]); return $this->albumData; } Results in a "Warning: Invalid argument supplied for foreach() in C:\public_html\development\Gallery.php5 on line 181" when I try to output the data in a foreach loop. Quote Link to comment Share on other sites More sharing options...
cgm225 Posted May 29, 2008 Author Share Posted May 29, 2008 Solved.. My findAlbum method was returning data to the findAlbums method, NOT the foreach loop... Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.