-3

I have this array:

$term = array();

For example:

$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;

So both items in term have the same 'item' value. How can i check if term item already has the same item in terms array before adding?

Bobby Redjeans
  • 575
  • 1
  • 4
  • 18
  • What have you tried so far, and what went wrong? – KIKO Software Nov 27 '21 at 12:16
  • Not entirely sure what logic you're trying to implement. Please share actual outcome vs. desired outcome (edit question). And show us what you've tried already, your best attempt, you might be closer to a solution than you think. – berend Nov 27 '21 at 13:36

1 Answers1

0

Did you try with 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";
   }
 ?>

Source: https://www.php.net/manual/en/function.in-array.php

Edit: Possible duplicate ### in_array() and multidimensional array

DeanTwit
  • 325
  • 4
  • 8