What is the best way to compare 2 arrays and echo out the values of the same content of the array in php? What is the best way to compare 2 arrays and echo out the values of the same content of the array in php? codeigniter codeigniter

What is the best way to compare 2 arrays and echo out the values of the same content of the array in php?


You could use array_intersect_key on the menus array and the flipped (to make the values the keys) access array:

$pages = array_intersect_key($menus, array_flip($access['pages_id']));

You could then iterate over the $pages variable in the same way as you are currently iterating over the $menus array.

Demo on 3v4l.org


I think using

  1. array_intersect
  2. array_diff