Jump to content

How to identify a killer in php


TinyBubbles

Recommended Posts

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. :((

 

 

Link to comment
https://forums.phpfreaks.com/topic/280388-how-to-identify-a-killer-in-php/
Share on other sites

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.";
}

 

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!  :happy-04:

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.