otuatail Posted November 17, 2007 Share Posted November 17, 2007 Thanks to those who replied to my array problem post. What I am attempting to do is create an expanding array, and call a function that pulls a record from a database table. Then search the aray for a value. The problem is the array will have to be in a session variable. I have tried the following without success. *** php page *** include ('functions.inc'); $me[] = array("1-1","2-2","3-3"); $_SESSION['Visits'] = $me; visited(1); *** functions file *** myfunction() { $list = $_SESSION['Visits']; $key = array_search($seek , $list); echo $key . "<br>"; // displays nothing echo count($list); // Displays 1 but array is 3 } Any sugestions on how to manage the array in a session. Help! Quote Link to comment Share on other sites More sharing options...
rajivgonsalves Posted November 17, 2007 Share Posted November 17, 2007 should be $me = array("1-1","2-2","3-3"); Quote Link to comment Share on other sites More sharing options...
otuatail Posted November 17, 2007 Author Share Posted November 17, 2007 Great thanks. Must brush up on my C/PHP programming. Desmond. Quote Link to comment Share on other sites More sharing options...
axiom82 Posted November 17, 2007 Share Posted November 17, 2007 Be careful how much memory your array takes up if it is expanding. It is almost always best to recall mysql records than store them into a php array which may exponentially wastes server memory. There is an easier way to add array data into the session... $_SESSION['users'][1]['id'] = 12043; $_SESSION['users'][1]['first_name'] = 'John'; $_SESSION['users'][1]['last_name'] = 'Smith'; $_SESSION['users'][2]['id'] = 10942; $_SESSION['users'][2]['first_name'] = 'Jane'; $_SESSION['users'][2]['last_name'] = 'Doe'; This format works fine with the print_r() function for debugging...here is the print_r() output for the $_SESSION structure above... Array ( [users] => Array ( [1] => Array ( [id] => 12043 [first_name] => John [last_name] => Smith ) [2] => Array ( [id] => 10942 [first_name] => Jane [last_name] => Doe ) ) ) 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.