MDanz Posted May 20, 2011 Share Posted May 20, 2011 i have an array in the loop but it isn't building up with results. i want it to check if the array exists, if not then create the array. Then in next loop it pushes a new value into the array. Below isn't working?... while($row=mysql_fetch_assoc($get)); { $key = $row['keyword']; $scope= $_SESSION['scope']; if (!is_array($scope)) { $scopenew = array($key); $_SESSION['scope'] = $scopenew; } else { $scopenew = array_push($scope, $key); $_SESSION['scope'] = $scopenew; } } Link to comment https://forums.phpfreaks.com/topic/236979-array-in-loop-help/ Share on other sites More sharing options...
fugix Posted May 20, 2011 Share Posted May 20, 2011 have you tried echoing $scopenew in both of your statements to see what your result are Link to comment https://forums.phpfreaks.com/topic/236979-array-in-loop-help/#findComment-1218120 Share on other sites More sharing options...
wildteen88 Posted May 20, 2011 Share Posted May 20, 2011 Are you wanting to add all the keywords returned from your query into the $_SESSION['scope'] array? If so all you need to do is while($row = mysql_fetch_assoc($get)); { $_SESSION['scope'][] = $row['keyword']; } Link to comment https://forums.phpfreaks.com/topic/236979-array-in-loop-help/#findComment-1218122 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.