How to find an object in an existing array of arrays

I am not sure if the title is understandable with my case here, since I am still considered noob in PHP.

Here is my code

// An object has property e.g. (ID, Name, Status)
// This function returns an array of object.
function getObjects ($pid) { //return objects }

$pids = { 2, 23, 41, 45, 56, 91, 105, 107, 210 };

$myArr = array();

foreach ($pids as $pid)
  $myObjects = getObjects($pid);

  if (count($myObjects) > 0)
    array_push($myArr, $myObjects);

if ( count($myArr) > 0 )
  $result = "You have " . count($myArr) . " pending object";

So, inside $myArr there are collections of $myObjects array, and each $myObjects array contains $myObject.

The problem is, in $myArr, I don’t want to have any similar $myObject (Let’s say no multiple same IDs).

Currently, the $result is..

You have 4 pending object

Currently in my real application, with those $pids, $myArr contains with 4 of $myObjects and each of these $myObjects contain only 1 of $myObject that has the same IDs.

Since they have similarities on their IDs, I wish my $result to be

You have 1 pending object

I am sorry for the bad explaination, I hope I made myself quite clear this far.

Source: php

Leave a Reply