0

Here i want to compare two array results where the results looks like this,array1 looks like this

array(7) { [0]=> string(6) "M" [1]=> string(7) "T" [2]=> string(9) "W" [3]=> string(8) "T" [4]=> string(6) "F" [5]=> string(8) "S" [6]=> string(6) "S" }

array2 looks like this

array(7) { [0]=> string(5) "15:00" [1]=> string(5) "14:00" [2]=> string(5) "13:00" [3]=> string(0) "" [4]=> string(5) "12:00" [5]=> string(5) "11:00" [6]=> string(5) "10:00" }

here i want to compare the first value of array1 with the first value of array2row with the second and if the value return true it should perform a function and if the value return empty it should perform another function

so i had done my code like this

<?php foreach($array1 as $index => $val)
{
    foreach($array2 as $index2 => $val2){?>
    //here i want to compare $val with $val2 to check $val2 is not empty or not
    <?php }
}?>
2
  • and what will be the comparing criteria? means sunday compares to 13:00 how? Commented May 15, 2018 at 12:41
  • monday should compare with 15:00 and tuesday should compare with 14:00 and so on Commented May 15, 2018 at 12:44

1 Answer 1

1

You should do something like that:

$array1 = array("Monday","Tuesday","Wednesday","Thursday","Friday","Saturday","Sunday");
$array2 = array("15:00","14:00","13:00","", "12:00","11:00","10:00");

foreach($array1 as $index => $val) {
    echo "compare $val to $array2[$index]  <br />";   
}

This code returns:

    compare Monday to 15:00 
    compare Tuesday to 14:00 
    compare Wednesday to 13:00 
    compare Thursday to 
    compare Friday to 12:00 
    compare Saturday to 11:00 
    compare Sunday to 10:00 
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.