[英]PHP Check if an array of strings contains any value from an array of substrings
[英]PHP check if array contains value from array with different key
我有這個數組:
$term = array();
例如:
$common_item = array('id' => 0, 'full_name' => 'my great name'); //etc
$first_item = array('name' => 'Robert', 'item' => $common_item);
$second_item = array('name' => 'Roberto', 'item' => $common_item);
$term[] = $first_item;
//check if terms already has an item with the same item(common_item) and don't add
$term[] = $second_item;
因此,術語中的兩個項目具有相同的“項目”值。 在添加之前,如何檢查術語項在術語數組中是否已經具有相同的項?
您是否嘗試過in_array()
function?
<?php
$os = array("Mac", "NT", "Irix", "Linux");
if (in_array("Irix", $os)) {
echo "Got Irix";
}
if (in_array("mac", $os)) {
echo "Got mac";
}
?>
資料來源: https://www.php.net/manual/en/function.in-array.php
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.