How to check if array is equal to the end of other array in PHP

2 Answers

0 votes
$myarray = [1, 4, -98, 10918, 120];

$ends = array_slice($myarray, -3, 3); 
    
if (array(-98, 10918, 120) == $ends)
    echo "yes";
else    
    echo "no";


 
/*
run: 

yes

*/

 



answered Oct 29, 2017 by avibootz
0 votes
$myarray = [1, 4, -98, 10918, 120];

$ends = array_slice($myarray, -3, 3); 
    
$arr = array(-98, 10918, 120);
 
if (empty(array_diff($arr, $ends)))
    echo "yes";
else    
    echo "no";


 
/*
run: 

yes

*/

 



answered Oct 29, 2017 by avibootz
...