theITvideos Posted October 8, 2010 Share Posted October 8, 2010 Hi there, I'm working on PHP webform and I have a variable called $weightInfo which has the value 5000|6000 Now I have a list of Arrays and I would like to see if our variable value (i.e 5000|6000) is in that list of Array: Here is the ArrayList: $WeightArray = array('' => '', '0|100' => '100g or Less', '101|250' => '101g to 250g', '251|500' => '251g to 500g', '501|1000' => '501g to 1kg', '1000|2000' => '1kg to 2kg', '2000|3000' => '2kg to 3kg', '3000|4000' => '3kg to 4kg', '4000|5000' => '4kg to 5kg', '5000|6000' => '5kg to 6kg', '6000|7000' => '6kg to 7kg', '7000|8000' => '7kg to 8kg', '8000|9000' => '8kg to 9kg', '9000|10000' => '9kg to 10kg', 'customValues' => 'Custom Values' ); Now as we can see, in this ArrayList, there is that value 5000|6000. How do we find this through code, do we need some kind of looping or how do we check it. Kindly reply. Thank you Link to comment https://forums.phpfreaks.com/topic/215466-searching-for-a-given-value-in-an-array/ Share on other sites More sharing options...
jcbones Posted October 8, 2010 Share Posted October 8, 2010 $key = '5000|6000';echo (array_key_exists($key,$WeightArray)) ? $WeightArray[$key] : 'Key does NOT exist.'; Link to comment https://forums.phpfreaks.com/topic/215466-searching-for-a-given-value-in-an-array/#findComment-1120415 Share on other sites More sharing options...
theITvideos Posted October 8, 2010 Author Share Posted October 8, 2010 $key = '5000|6000';echo (array_key_exists($key,$WeightArray)) ? $WeightArray[$key] : 'Key does NOT exist.'; Thank you Bro! It worked!! Link to comment https://forums.phpfreaks.com/topic/215466-searching-for-a-given-value-in-an-array/#findComment-1120417 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.