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????
finding the largest of three arrays???
Moderator: General Moderators
- raghavan20
- DevNet Resident
- Posts: 1451
- Joined: Sat Jun 11, 2005 6:57 am
- Location: London, UK
- Contact:
- John Cartwright
- Site Admin
- Posts: 11470
- Joined: Tue Dec 23, 2003 2:10 am
- Location: Toronto
- Contact:
Code: Select all
$arrayCount['array1'] = count($array1);
$arrayCount['array2'] = count($array2);
$arrayCount['array3'] = count($array3);
$max = max($arrayCount);