irkevin Posted March 15, 2010 Share Posted March 15, 2010 Hi, I'm lost, I don't know if this is possible using PHP, guess I will have to ask. Here it goes. Below are some array: Array ( [0] => 1 [1] => ps2 [2] => game ) Array ( [0] => 2 ) Array ( [0] => 3 [1] => game ) As you can see, the first array has more data in it, how do I tell PHP to use only the array with more data? I hope this is possible. Please help guys. Quote Link to comment Share on other sites More sharing options...
simshaun Posted March 15, 2010 Share Posted March 15, 2010 You can run count() on each array to find the largest one. Quote Link to comment Share on other sites More sharing options...
irkevin Posted March 15, 2010 Author Share Posted March 15, 2010 Yes sure, but then, how do I tell php to make use of the largest one? Quote Link to comment Share on other sites More sharing options...
StathisG Posted March 15, 2010 Share Posted March 15, 2010 Just a quick example I can think of now: $array1 = array(1,2,3); $array2 = array(1,2); $array3 = array(1,2,3,4); $allArrays = array($array1 , $array2, $array3); $count = 0; for ($i=0; $i<sizeof($allArrays); $i++) { $result = count($allArrays[$i]); if ($result>$count) { $count = $result; $largerArray = $allArrays[$i]; } } print_r($largerArray); Quote Link to comment Share on other sites More sharing options...
irkevin Posted March 15, 2010 Author Share Posted March 15, 2010 I'll try this bro ! Will let u know in 10 mins or so Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.