jasmeet Posted August 31, 2013 Share Posted August 31, 2013 when i click on image1 with id=1, it stores in session and when i click on image2 with id=2, it stores in session too next to the first one, and when i click on image3 with id=3, it stores in session next to id=2. and so on.... i hope you understand what i am asking .... need help. i know how to get value from array.... like <?php// begin the sessionsession_start(); // create an array$my_array=array('cat', 'dog', 'mouse', 'bird', 'crocodile', 'wombat', 'koala', 'kangaroo'); // put the array in a session variable$_SESSION['animals']=$my_array; // a little message to say we have done itecho 'Putting array into a session variable';// loop through the session array with foreachforeach($_SESSION['animals'] as $key=>$value) { // and print out the values echo 'The value of $_SESSION['."'".$key."'".'] is '."'".$value."'".' <br />'; }?> /*************************************************************************************************************************************/ but wat i want is, cat ,dog,mouse,bird,crocodile,wombat,koala,kangaroo ... stored in array when i click on them.... i hope you understand.. please help!!! thanks and regards, jazz.. Link to comment https://forums.phpfreaks.com/topic/281720-array-as-session-variable-on-click-to-some-image/ Share on other sites More sharing options...
0xMatt Posted August 31, 2013 Share Posted August 31, 2013 <?phpsession_start(); $animals = array('cat', 'dog', 'mouse', 'bird', 'crocodile', 'wombat', 'koala', 'kangaroo'); if(isset($_GET['add_animal'])){$_SESSION['animals'][$animals[$_GET['add_animal']]] = 1;} echo '<h1>Animals to choose from</h1>'; foreach($animals as $key=> $value){// and print out the valuesecho "<a href='test2.php?add_animal={$key}'>{$value}</a></br>";} echo '<br/><br/>'; $added_animals = '';foreach($_SESSION['animals'] as $animal => $value){$added_animals .= $animal. ',';} echo 'The animal you have added are: ' . $added_animals; Try that. Obviously change test2.php t your file name before you try it. Link to comment https://forums.phpfreaks.com/topic/281720-array-as-session-variable-on-click-to-some-image/#findComment-1447506 Share on other sites More sharing options...
jasmeet Posted August 31, 2013 Author Share Posted August 31, 2013 thankew ... 0xMatt.... :) Link to comment https://forums.phpfreaks.com/topic/281720-array-as-session-variable-on-click-to-some-image/#findComment-1447514 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.