gpt4 book ai didi

php - 如何找到包含在数组中的值中的值?

转载 作者:可可西里 更新时间:2023-10-31 23:02:16 25 4
gpt4 key购买 nike

如果我有数组:

$os = array("Mac", "NT", "Irix", "Linux");

我知道如果我想在 $os 中找到 "Mac" 可以使用 in_array()

但是我有数组:

$os = array( [1] => "Mac/OSX", [2] => "PC/Windows" );

我想看看 "Mac" 是否包含在 $os 中?

最佳答案

尝试:

$example = array("Mac/OSX","PC/Windows" );
$searchword = 'Mac';
$matches = array_filter($example, function($var) use ($searchword) { return preg_match("/\b$searchword\b/i", $var); });

关于php - 如何找到包含在数组中的值中的值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37584824/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com