doudao2954 2015-10-05 19:20
浏览 30
已采纳

PHP:从数组检查和读取[重复]

This question already has an answer here:

I have an array like :-

$arr = array(
    "Sci-Fi",
    "Action"
);

How can check if Action exists in this array , And how can convert it to (Sci-Fi,Action)

Thankx

</div>
  • 写回答

1条回答 默认 最新

  • douji3426 2015-10-05 19:25
    关注

    In your question $arr is the array. First we'll check if 'Action' is in the array.

        if(in_array('Action',$arr)){
          //in_array checks if 'Action' is in the array
          echo "Action is in the array!";
        }
    

    Now we need to "implode" the array to turn it into a string.

        echo "(" . implode(',', $arr) . ")";
        //implode glues the parts of your array together into a string using the supplied "glue", in this case a comma.
    

    php.net has it all documented, but I know it's hard to just know what a function name is, especially something cryptic like implode. When you're learning it's nice to get a friendly answer.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 nginx 配置静态html访问 ,后台登录时页面始终被重定向到登录页,无法访问到后台的静态html页
  • ¥20 自动登录的j2ee程序编译
  • ¥15 echarts如何对X轴进行分组
  • ¥15 维纳滤波器的实验题及计算机实现,求解
  • ¥15 fluent模拟静态气体扩散
  • ¥15 java根据模板,生成word文档,需要带目录
  • ¥15 广告联盟的兜底广告是什么意思
  • ¥15 如何证明高斯噪声的包络公式
  • ¥150 寻找王者荣耀开发作者,合作或者解答
  • ¥15 关于cpci总线的几个问题,别用人工智能回答