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. Link to comment https://forums.phpfreaks.com/topic/195331-php-to-use-the-array-with-highest-number-of-keys/ 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. Link to comment https://forums.phpfreaks.com/topic/195331-php-to-use-the-array-with-highest-number-of-keys/#findComment-1026480 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? Link to comment https://forums.phpfreaks.com/topic/195331-php-to-use-the-array-with-highest-number-of-keys/#findComment-1026488 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); Link to comment https://forums.phpfreaks.com/topic/195331-php-to-use-the-array-with-highest-number-of-keys/#findComment-1026493 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 Link to comment https://forums.phpfreaks.com/topic/195331-php-to-use-the-array-with-highest-number-of-keys/#findComment-1026498 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.