<?php

  $m = range(1,1000000); // from one to a million
  $s = range(1,1000000);

// Use array_intersect to return all $m values that are also in $s
  $tstart = microtime(true);
  echo "+--------------------------------------------------+\n";
  //print_r (array_intersect($m,$s));
  $tend = microtime(true);
  (double)$time = $tend - $tstart;

  echo "|   array_intersect took $time \n";
  
// Use array_flip and isset to return all $m values that are also in $s
  $tstart = microtime(true);
  $f = array_flip($s);
// $u will hold the intersected values
  $u = [];
  foreach ($m as $v) {
    if (isset($f[$v])) $u[] = $v;
  }
  //print_r ($u);
  $tend = microtime(true);
  (double)$time = $tend - $tstart;
  echo "|\n";
  echo "|   array_flip took $time \n";
  echo "+--------------------------------------------------+";