我有两个用逗号分隔的整数字符串。一个是文章类型的ID,被调用的脚本被告知要显示(通过POST),另一个是当前登录的用户实际有权查看的文章类型的ID。
我想生成第三个用逗号分隔的整数列表,其中包含两个值。例如:
$want_to_see = "1,5,6,8,10"
$current_user_can_see = "1,3,6,10,20"
$show = "1,6,10"
您可以explode
使用array_intersect
来将两个字符串分成数组,然后使用来仅保留公共值:
$want_to_see = explode(",", "1,5,6,8,10");
$current_user_can_see = explode(",", "1,3,6,10,20")
// Array of common elements:
$show = array_intersect($want_to_see, $current_user_can_see);
// If you want it as a string:
$show_str = implode(",", $show);
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句