Jump to content

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:

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.