hi to all

how do i pass parameters value using call back function in array_list

<?php
  class A
  {
  public $Menu = array(
			array("LeftValue"=>5,
				  "name"=>'test' 
					),
			array("LeftValue"=>6,
				  "name"=>'test one' 
					),
			array("LeftValue"=>7,
				  "name"=>'test two' 
					),
			array("LeftValue"=>8,
				  "name"=>'test three' 
					),
			array("LeftValue"=>9,
				  "name"=>'test four' 
					),
			array("LeftValue"=>10,
				  "name"=>'test five' 
					),


				);
public $a;
private function BreadCrumbsMenu($MenuOutput,$a,$b) // this should receive paramers
{

	if($MenuOutput['LeftValue'] > $a && $MenuOutput['LeftValue'] < $b)
	{
		return true;
	}
	else
	{
		return false;
	}
}

public function test()
{

$BreadMenuOutput = array_filter($this->Menu, array($this, 'BreadCrumbsMenu',array(2,3))); // this should pass paramerers
}
  }
  $test = new A();
  $test->test();
?>

when executed

array_filter() [function.array-filter]: The second argument, 'Array', should be a valid callback in

TIA

    Hi

    Not too experienced with array_filter (only used it a couple of times) but as far as I know you can't use an array as a function reference under any cirsumstances. I can't really see how you would be able to pass additional variables directly to the callback function either, since array_filter just passes the values in the array to the callback.

    However, since it's all in one class, maybe you could get at some private variables inside the callback function using this->varname, and create another method to modify those variables? (If you need to - you appear to be passing static values as the codes stands...)

    Sorry I can't be mor help

      hmm
      I think using array_filter is overkill here.
      you can just have BreadCrumbsMenu() iterate through $this->menu, and pass it your $a and $b directly, ie:
      $BreadMenuOutput = $this->BreadCrumbsMenu(2,3);
      then the actual fun BreadCrumbsMenu just does something like:

      private function BreadCrumbsMenu($a,$b)
      $return_array = array();
      foreach ( $this->Menu as $item )
      {
        if($item['LeftValue'] > $a && $item['LeftValue'] < $b) 
        {
          $return_array[] = $item;
        }
      }
      return $return_array;
      }
      
        Write a Reply...