TinyBubbles Posted July 22, 2013 Share Posted July 22, 2013 Hello guys! I'm new here at phpfreaks. but I'm not new in Php programming, I'm just stuck with this killer problem. So can you guys help me solve the problem? so here's the problem A person was murdered in a party. There were 5 people involved. The murder weapon used was a gun & was killed at the dining hall. weapons(inputs) location: gun = 1 kitchen = 0 rope =0 bedroom = 0 axe = 0 livingroom = 0 poison = 0 dining hall = 1 Conditions: Joseph Kitchen & livingroom w/ rope & gun Mary bedroom & lvingroom w/ poison & rope Peter bedroom & dining w/ axe & poison Julie dining & bedroom w/ gun & poison John dining & living w/rope & axe NOTE: JULIE is the killer. What I need is how to display that Julie is the killer. that is the only thing that should appear in the window. Please Help me with this. ( Quote Link to comment https://forums.phpfreaks.com/topic/280388-how-to-identify-a-killer-in-php/ Share on other sites More sharing options...
TinyBubbles Posted July 22, 2013 Author Share Posted July 22, 2013 btw: this problem is limited to if-else, for-loop methods. THanks ) Quote Link to comment https://forums.phpfreaks.com/topic/280388-how-to-identify-a-killer-in-php/#findComment-1441637 Share on other sites More sharing options...
mac_gyver Posted July 22, 2013 Share Posted July 22, 2013 one possible way of solving your assignment - $data['Joseph'] = array('loc'=>array('kitchen','livingroom'),'wep'=>array('rope','gun')); $data['Julie'] = array('loc'=>array('dining','bedroom'),'wep'=>array('gun','poison')); // ... other data as desired $wep = 'gun'; $loc = 'dining'; $found = false; foreach($data as $person=>$arr){ if(in_array($wep,$arr['wep']) && in_array($loc,$arr['loc'])){ $found = $person; break; // stop at first match } } if($found){ echo "$found did it."; } else { echo "No match."; } Quote Link to comment https://forums.phpfreaks.com/topic/280388-how-to-identify-a-killer-in-php/#findComment-1441639 Share on other sites More sharing options...
TinyBubbles Posted July 22, 2013 Author Share Posted July 22, 2013 one possible way of solving your assignment - $data['Joseph'] = array('loc'=>array('kitchen','livingroom'),'wep'=>array('rope','gun')); $data['Julie'] = array('loc'=>array('dining','bedroom'),'wep'=>array('gun','poison')); // ... other data as desired $wep = 'gun'; $loc = 'dining'; $found = false; foreach($data as $person=>$arr){ if(in_array($wep,$arr['wep']) && in_array($loc,$arr['loc'])){ $found = $person; break; // stop at first match } } if($found){ echo "$found did it."; } else { echo "No match."; } Thanks so much! Quote Link to comment https://forums.phpfreaks.com/topic/280388-how-to-identify-a-killer-in-php/#findComment-1441640 Share on other sites More sharing options...
AbraCadaver Posted July 22, 2013 Share Posted July 22, 2013 Whoa, whoa, whoa...!!! Where are Professor Plum and Colonel Mustard? Quote Link to comment https://forums.phpfreaks.com/topic/280388-how-to-identify-a-killer-in-php/#findComment-1441686 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.