My Array $json
如下所示:
Array (
[0] => Array ( [poulecode] => 495271
[teamcode] => 277986
[teamnaam] => JO19-1 (0225 Onder 19 competitie (najaar)) )
[1] => Array ( [poulecode] => 500027
[teamcode] => 277986
[teamnaam] => JO19-1 (B3200 Zwaluwen jeugdbeker Onder 19 poule) )
[2] => Array ( [poulecode] => 524572
[teamcode] => 277986
[teamnaam] => JO19-1 (0227 Onder 19 competitie (voorjaar)) )
)
如何通过搜索包含某个字符串“voorjaar”的$competitiecode
来挑选(设置变量poulecode (524572)
)?
我一直在使用teamnaam's ( JO19-1 (0227 Onder 19 competitie (voorjaar)) )
和array_filter
进行此操作,但我似乎无法弄明白。
到目前为止,这是我的一段代码:
array_column
答案 0 :(得分:2)
您可以使用foreach
循环:
$find = Array();
$search = 'voorjaar';
foreach($json as $j) {
if (strpos($j['teamnaam'], $search) !== false) {
$find[] = Array(
'poulecode' => $j['poulecode']
);
}
}
答案 1 :(得分:1)
Public Function IsConnectedToInternet() As Boolean
If My.Computer.Network.IsAvailable Then
Try
Dim IPHost As IPHostEntry = Dns.GetHostEntry("www.google.com")
Return True
Catch
Return False
End Try
Else
Return False
End If
End Function
答案 2 :(得分:0)
你的array_filter()
应该得到这个论点:
$keys = array_filter(array_column($json, $Teamnaam), function($item) use ($findme){
if (strpos($item['teamnaam'], $findme) !== false) {
return true;
}
return false;
});
$keys
现在是一个数组。