Page 1 of 1

array_filter() and for () problem....

Posted: Mon Dec 08, 2003 11:06 pm
by arbocenc
Hi,

I'm stuck in a php problem:

Code: Select all

function filtre_editors($var) {
    return ($varї"manufacturer_id"] == $listado_editores_dosї$ii]);  //funciona si li poso 29..
}

for ($ii=0; $ii<sizeof($listado_editores_dos); $ii++) &#123;
$order_filtrada = array_filter($order->products, "filtre_editors"); 
sort ($order_filtrada);
&#125;
This code doesn't run because $listado_editores_dos[$ii] has a value after the function definition... And I can not add a $ii like:

Code: Select all

$order_filtrada = array_filter($order->products, "filtre_editors(,Sii)");  because it's wrong...
My PHP skills are no good and I can't look after the solution... Any ideas?

Regards,

Joan

Posted: Tue Dec 09, 2003 1:03 am
by Weirdan
You can take advantage of the internal array pointers:

Code: Select all

function filtre_editors($var) { 
    global $listado_editores_dos;
    return ($var["manufacturer_id"] == current($listado_editores_dos));  //funciona si li poso 29.. 
} 

reset($listado_editores_dos);
do{ 
  $order_filtrada = array_filter($order->products, "filtre_editors");
  sort ($order_filtrada); 
}while (false!==next($listado_editores_dos));

Posted: Tue Dec 09, 2003 7:53 am
by arbocenc
Gorgeous!

I think it will run...

Thanks a lot!

Joan