We Must Design Posted October 9, 2007 Share Posted October 9, 2007 I have created an array by using the following code: $_SESSION['favoriteArray'][] = $_GET['cocktail']; This works fine. Then I want to use the in_array function to see if a variable is in an the array before I add it. This is where the problem is, I am not sure I have the right syntax. Here is the code anyway: if (in_array ($cocktail_name, $_SESSION['favoriteArray'][]); and here is the error message: Fatal error: Cannot use [] for reading in /home/must/public_html/cocktails/index.php on line 74 Thanks, Chris Quote Link to comment https://forums.phpfreaks.com/topic/72426-in_array/ Share on other sites More sharing options...
Aureole Posted October 9, 2007 Share Posted October 9, 2007 <?php $some_variable = 1; $some_array = array(1, 'lump', 'or', 2); if (in_array($some_variable, $some_array)) { echo('Muffins.'); } ?> That's how you use it, but you're problem is putting [] after your session variable, you can't do that... $_SESSION['favoriteArray'][] ...as far as I know. Quote Link to comment https://forums.phpfreaks.com/topic/72426-in_array/#findComment-365226 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.