I really need help:

	/**
	 * Resultset version of "in_array" function to display boolean results of finding a resultset-configured object in the resultset
	 *
 	 * @access private
	 * @param int $thisID
	 * @param object $result
	 * @return boolean
	 * @see [url]http://us2.php.net/manual/en/function.in-array.php[/url]
	 */
	function in_result($thisID, $result) {							// BOOLEAN METHOD
		global $section;
		$id = $_REQUEST['id'];
		$associatedSection = $this->getAssociatedSection();
		$obj->base_section_name = "$section";
		$obj->base_section_value = $id;
		$obj->associated_section_name = "$associatedSection";
		$obj->associated_section_value = $thisID;
		return in_array($obj, $result);
	}

I am trying to do a version of in_array() for object arrays. I have an array consisting of objects, and I have to find a matching object in that array, and in_array() fails for me in this case.

What do I do? I can't have looping because this function is to be used within a looping construct.

Thanx
Phil

    so i am guessing $result is your array.

    but even in an object don't you have to get the value of whatever you want.

    so maybe in your object class you need to define a function/method that returns this:

    $obj->base_section_name = "$section";
    $obj->base_section_value = $id;
    $obj->associated_section_name = "$associatedSection";
    $obj->associated_section_value = $thisID;

    function getObjectValue()
    {
    return/print $this->base_section_name.','.$this->base_section_value...etc
    }

    then you can call that in your in results after you have set the values.

    so you set your values:

    $obj->base_section_name = "$section";
    $obj->base_section_value = $id;
    $obj->associated_section_name = "$associatedSection";
    $obj->associated_section_value = $thisID;

    now return in_array($getObjectValue(), $results)

    hope this is what you want.

      That would look for a particular scalar value in an object array, that wouldn't work because the particular scalar value may be equal but everything else in that object must also match..

      That is, the object parameter ($obj) must have every property value match any object's set of properties in the array, like:

      if ($result[0] === $obj) print_r("MATCH!");
      

      Phil

        Got it!

        	/**
        	 * Resultset version of "in_array" function to display boolean results of finding a resultset-configured object in the resultset
        	 *
         	 * @access private
        	 * @param int $thisID
        	 * @param object $result
        	 * @return boolean
        	 * @see [url]http://us2.php.net/manual/en/function.in-array.php[/url]
        	 */
        	function in_result($thisID, $result) {							// BOOLEAN METHOD
        		global $section;
        		$id = ($this->id) ? $this->id : $_REQUEST['id'];
        		$associatedSection = $this->getAssociatedSection();
        		$obj->base_section_name = "$section";
        		$obj->base_section_value = $id;
        		$obj->associated_section_name = "$associatedSection";
        		$obj->associated_section_value = $thisID;
        		$tempResult = $result;
        		array_walk($tempResult, create_function('$a', 'return serialize($a);'));
        		return in_array(serialize($obj), $tempResult);
        	}
        

        Phil

          Write a Reply...