douan2907 2014-12-11 09:50
浏览 101
已采纳

php从两个数组中获取匹配值

I Have two arrays like this

$array1 = Array ( [0] => Dutch [1] => Kannada [2] => Vietnamese [3] => Belarusian );
$array2 = Array ( [0] => English [1] => Germany [2] => Vietnamese [3] => Spanish [4] => Hindi );

I want to get the same values present in both arrays. So for that I used array_intersect like this

<?php
$array1 = Array ( [0] => Dutch [1] => Kannada [2] => Vietnamese [3] => Belarusian );
$array2 = Array ( [0] => English [1] => Germany [2] => Vietnamese [3] => Spanish )
$result = array_intersect($array1, $array2);
print_r($result);
?>

But its not showing the matching values. Even it is showing the error like

Parse error: syntax error, unexpected '[', expecting ')'

I think the array code structure is fine then why I am getting this error and not getting the matching values from two arrays? Any help and suggestions will be really appreciable. Thanks

  • 写回答

2条回答 默认 最新

  • dqhgjay5753 2014-12-11 09:52
    关注

    This should work for you:

    (First you declared your array wrong and forgot a ;)

    $array1 = array ("Dutch", "Kannada", "Vietnamese", "Belarusian");
    $array2 = array ("English", "Germany", "Vietnamese", "Spanish");
    $result = array_intersect($array1, $array2);
    print_r($result);
    

    Output:

    Array ( [2] => Vietnamese )
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料