cooldude832 Posted December 8, 2007 Share Posted December 8, 2007 I have an array in my session variable that is like $_SESSION['recent_items'][0]['ItemNumber'] = 1; $_SESSION['recent_items'][1]['ItemNumber'] = 2; $_SESSION['recent_items'][2]['ItemNumber'] = 3; and I want to make sure somethign isn't already in the array with that name so if I say <?Php $Item_num = 2; if(in_array($item_num,$_SESSION['recent_items'])){ echo "yes"; } ?> should it echo yes??? Link to comment https://forums.phpfreaks.com/topic/80723-will-this-work-with-in_array/ Share on other sites More sharing options...
PFMaBiSmAd Posted December 8, 2007 Share Posted December 8, 2007 It works, if your array is structured correctly (tested) - <?php session_start(); $_SESSION['recent_items']['ItemNumber'][0] = 1; $_SESSION['recent_items']['ItemNumber'][1] = 2; $_SESSION['recent_items']['ItemNumber'][2] = 3; $item_num = 2; if(in_array($item_num,$_SESSION['recent_items']['ItemNumber'])){ echo "yes"; } Link to comment https://forums.phpfreaks.com/topic/80723-will-this-work-with-in_array/#findComment-409471 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.