jdubwelch Posted November 10, 2006 Share Posted November 10, 2006 i have an array in the format: [family] => day that they have a reservation[code]eventsArray( [Jason & Deena] => 29 [Bob & Krista] => 9 [Marolyn] => 15 [J&D] => 17 [bob & sally] => 22 [Bob & Sally] => 25)[/code]I want to search throught the array and if there is an event on that day, print the key for it. In this case the key is the name of the family. [code]for ($i=1; $i<=31; $i++) { if (in_array($i, $eventsArray)) { echo "yes, there is an event on $i<br>"; } }[/code]how do i get the name of the key that has the value $i? Link to comment https://forums.phpfreaks.com/topic/26795-getting-the-name-of-the-key/ Share on other sites More sharing options...
fiddy Posted November 10, 2006 Share Posted November 10, 2006 Please try using... for each Link to comment https://forums.phpfreaks.com/topic/26795-getting-the-name-of-the-key/#findComment-122538 Share on other sites More sharing options...
btherl Posted November 10, 2006 Share Posted November 10, 2006 You can find it using [code=php:0]$families = array_keys($eventsArray, $i);[/code]That will return an array of all the families who have a reservation on that day. Link to comment https://forums.phpfreaks.com/topic/26795-getting-the-name-of-the-key/#findComment-122540 Share on other sites More sharing options...
jdubwelch Posted November 10, 2006 Author Share Posted November 10, 2006 thanks...i tried array_flip too and that worked, but your way is better. Link to comment https://forums.phpfreaks.com/topic/26795-getting-the-name-of-the-key/#findComment-122543 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.