douan2907 2014-12-11 01: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 01: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条)
编辑
预览

报告相同问题?

悬赏问题

  • ¥40 selenium访问信用中国
  • ¥15 电视大赛投票系统的c语言代码怎么做
  • ¥20 在搭建fabric网络过程中遇到“无法使用新的生命周期”的报错
  • ¥15 Python中关于代码运行报错的问题
  • ¥500 python 的API,有酬谢
  • ¥15 软件冲突问题,软件残留问题
  • ¥30 有没有人会写hLDA,有偿求写,我有一个文档,想通过hLDA得出这个文档的层次主题,有偿有偿!
  • ¥50 有没有人会写hLDA,有偿求写,我有一个文档,想通过hLDA得出这个文档的层次主题,有偿有偿!
  • ¥15 alpha101因子里哪些适合crypto?
  • ¥15 ctrl win alt 键一直触发
手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部