willaguila Posted September 22, 2009 Share Posted September 22, 2009 Hi folks! I'm trying to return an array that was created in a class method to the calling script as follows: class images extends DatabaseObject { public function image_inodes_retrieve() { $nodelist = array(); global $database; $clean_id = $database->escape_value($this->masterid); $sql = "SELECT * FROM filedata WHERE masterid = "; $sql .= $clean_id; $sql .= " ORDER BY id"; if (!$result = $database->query($sql)) { die("Failure to retrieve list of file inodes"); } while ($current = $database->fetch_object($result)) { $nodelist[] = $current->id; //return $nodelist; } } } If I echo the array with in the method using print_r() after calling from the original script as follows: $image_info_retrieved = new images(); $nodes = $image_info_retrieved->image_inodes_retrieve(); The array structure is printed correctly! But if I try to return the array to the original script for example the array is truncated! I know I'm doing it incorrectly so if you know how to do this please enlighten me? Quote Link to comment https://forums.phpfreaks.com/topic/175062-solved-how-to-return-an-array-from-with-in-a-class-method/ Share on other sites More sharing options...
.josh Posted September 22, 2009 Share Posted September 22, 2009 put the return outside of your loop. Once it's triggered the first time, it exits the loop and whole method. Quote Link to comment https://forums.phpfreaks.com/topic/175062-solved-how-to-return-an-array-from-with-in-a-class-method/#findComment-922661 Share on other sites More sharing options...
willaguila Posted September 22, 2009 Author Share Posted September 22, 2009 Ok that was stupid of me! This works! Quote Link to comment https://forums.phpfreaks.com/topic/175062-solved-how-to-return-an-array-from-with-in-a-class-method/#findComment-922885 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.