phpnewone Posted November 26, 2010 Share Posted November 26, 2010 Hello. I am just trying to sort an array alphabetically. Here's the code I'm using: function GetAssocCharities($registrationNo) { $db = ConnectionString::ConnectTo_www_ago_mo_gov_data(); $sqlstring = "SELECT * FROM charityPartners where RegistrationNo LIKE '$registrationNo' ORDER BY Name"; $results = @mysql_query($sqlstring); $org = null; while ($resultArray = mysql_fetch_array($results)) { $temp = new Registrants($resultArray['ARegNoFormatted'], $resultArray); $org[] = $temp; } return asort($org); } When I try to loop through the array using a foreach loop, I get an error that Invalid argument supplied for foreach(). Here's my foreach loop: $lstCharities = OrgQueries::GetAssocCharities($registrant->RegNoFormatted); foreach($lstCharities as $c) { //dom something here } I'm sure its something with not understanding list v array or something or that nature, but I'm not having much luck figuring it out with google. Thanks! Quote Link to comment Share on other sites More sharing options...
JasonLewis Posted November 27, 2010 Share Posted November 27, 2010 The sorting functions return true or false, depending on success or failure. So instead of returning an array you are now either returning true or false, hence why it is throwing the error at you. You simply call asort() then return the variable normally. asort($org); return $org; Always make sure you check the manual my friend. 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.