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

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
arbocenc
Forum Newbie
Posts: 2
Joined: Mon Dec 08, 2003 11:06 pm

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

Post 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
User avatar
Weirdan
Moderator
Posts: 5978
Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine

Post 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));
arbocenc
Forum Newbie
Posts: 2
Joined: Mon Dec 08, 2003 11:06 pm

Post by arbocenc »

Gorgeous!

I think it will run...

Thanks a lot!

Joan
Post Reply