[0]=>
  array {
    "id" => 11,
    "rule"=> "rule 1"
  },
[1]=>
  array {
    "id" => 40,
    "rule"=> "rule 2"
  }
[3]=>
  array {
    "id" => 55,
    "rule"=> "rule 3"
  }
[4]=>
  array {
    "id" => 40,
    "rule"=> "rule 4"
  }

How am I able to unset the elements with id = 40 to get the following array?

[0]=>
  array {
    "id" => 11,
    "rule"=> "rule 1"
  },
[1]=>
  array {
    "id" => 55,
    "rule"=> "rule 3"
  }

Do I need to do a foreach cycle / array check / unset?
Or is there any php function for it?

    One way would be to use [man]array_filter/man and create your own callback function that returns boolean FALSE if the id value is equal to 40.

      If possible, use the ids as top level array keys when creating the array instead.

        johanafm wrote:

        If possible, use the ids as top level array keys when creating the array instead.

        I was going to suggest that, but I noticed that there are two elements with an id of 40. Of course, you could still use IDs as array indexes, with the corresponding values themselves arrays.

          Write a Reply...