finding the largest of three arrays???
Posted: Mon Feb 27, 2006 12:16 pm
This is a simple problem and I am thinking of using either PHP functions or by some logic to do it with minimum number of steps....
I have got three arrays which has unknown number of elements in each. We have to find which array has the maximum number of elements in it...
few ways i have thought of:
1. using a simple if:
a>b & a>c
then a
else b > c
then b else c
2. this can be done in a line using ternary operators
3. assigning arrays and their count as associative arrays and sorting by keys which can help us get the array with maximum elements
array('a'=>count(a), 'b' => count(b), 'c' => count(c))
sort by key...and last element would be having max number of elements.
can you guys think of anything better????
I have got three arrays which has unknown number of elements in each. We have to find which array has the maximum number of elements in it...
few ways i have thought of:
1. using a simple if:
a>b & a>c
then a
else b > c
then b else c
2. this can be done in a line using ternary operators
3. assigning arrays and their count as associative arrays and sorting by keys which can help us get the array with maximum elements
array('a'=>count(a), 'b' => count(b), 'c' => count(c))
sort by key...and last element would be having max number of elements.
can you guys think of anything better????