Jsp
Jsp

Reputation: 176

PHP Repeat n times inside a function

I am trying to use item[1],item[2]... item[n] inside php functions like array_diff, max etc.

I use foreach loop like this to get the items

$n=1;
foreach ($arrays as $array) {
    $item[$n] = $array;
    $n++;  
}

# how can I define item[1] through item[n] like:
print_r(max(item[1],item[2]...item[n]));
print_r(array_diff(item[1],item[2]...item[n]));

I searched but could not find a solution, please point me to the url if this has already been answered. Thanks.

Upvotes: 0

Views: 272

Answers (1)

Elias Nicolas
Elias Nicolas

Reputation: 775

Even though I don't see a problem, you can do this: Hope it helps

foreach ($arrays as $k=>$array) {
    $item[$k] = $array;
}
print_r(max($item));
print_r(array_diff($arrays,$item));

Upvotes: 2

Related Questions