-2

I need some helps to compare some arrays with php, basically I have two arrays (mission and employee) :

Array mission :

Array(
[0] => Array (
    [days] => Monday
    [hours] => 1,0,0,0,0,0
)
[1] => Array
    (
        [days] => Tuesday
        [hours] => 1,1,0,0,0,1
    )
)

Array employee :

Array(
[0] => Array (
    [days] => Monday
    [hours] => 1,0,0,0,0,0
)
[1] => Array
    (
        [days] => Tuesday
        [hours] => 1,1,0,0,0,1
    )
)
[1] => Array
    (
        [days] => Wednesday
        [hours] => 1,1,0,0,0,1
    )
)

The aim is to compare if employee is available for a mission, it means if employee is available (above case) Monday and Tuesday with included hours to work (1 and 0 represents hours and position of each item is very important).

Firstly employee is not available if number of mission days is superior to employee day :

foreach ($mission as $m) {
    # code...
    $m_days[] = $m['days'];
    foreach ($employee as $e) {
        $e_days[] = $e['days'];
    }
    $i++;
}
/// First condition if m_days > e_days so valid
$valid = (sizeof($m_days) > sizeof($e_days)) ? true : false;

After that I have no idea to compare if employee is at least available for mission hours, for example if mission is a Monday with hours : 1,1,0,0,0,1 and employee is free for Monday with hours : 1,1,1,0,0,1 he can take the mission, but if he is available Monday with hours : 1,0,0,0,0,1 he cannot take the mission.

With array_diff it is not working as demonstrated here

Could you help me please ? Thank you.

Rahajason
  • 23
  • 1
  • 7

1 Answers1

0

Try using array_diff

Example array_diff()

<?php
$array1 = array("a" => "car", "bike", "skateboard", "bike");
$array2 = array("b" => "car", "boat", "bike");
$result = array_diff($array1, $array2);

print_r($result);
?>

Multiple occurrences in $array1 are all treated the same way. This will output :

Array
(
    [1] => skateboard
)
Victor York
  • 1,621
  • 4
  • 20
  • 55
  • Hello, thank you for your response but I think area_diff will do the job, based on your script my arrays output : Please see : http://sandbox.onlinephpfunctions.com/code/3bd017dc429a431ab84b5b701fcd7d8dc3a947d8
    Notice: Array to string conversion in [...][...] on line 5

    Notice: Array to string conversion in [...][...] on line 5
    Array ( )
    – Rahajason Jan 20 '17 at 17:14