mkosmosports Posted January 28, 2007 Share Posted January 28, 2007 Ive got this multidimensional array:Array( [200701] => Array ( [0] => France [1] => Serbia ) [200611] => Array ( [0] => Italy [1] => Italy [2] => England [3] => England ) [200610] => Array ( [0] => England [1] => England ))Im interested in doing three things with it:1. Get the Max year/month value, so 200701.2. Clean up the array to avoid duplicates in the subarray.Any ideas?Many thanks! Quote Link to comment Share on other sites More sharing options...
mkosmosports Posted January 28, 2007 Author Share Posted January 28, 2007 :P. Let me rephrase that question. Is there a way to use the max function on the value of the ID in a associative array where that value is a certain number? Quote Link to comment Share on other sites More sharing options...
mkosmosports Posted January 28, 2007 Author Share Posted January 28, 2007 hmmm....I guess this is impossible....ok, Ill have to rearrange some things then...Thanks! Quote Link to comment Share on other sites More sharing options...
mkosmosports Posted January 28, 2007 Author Share Posted January 28, 2007 Damn, I hate being persistent and annoying but is this really impossible?? I mean, there is gotta be a way to somehow retrieve the highest value of the ID in an associative array and then being able to use it...I promise Ill help people out when I gain enough knowledge... :P Quote Link to comment Share on other sites More sharing options...
Jessica Posted January 28, 2007 Share Posted January 28, 2007 sort(); then $array[0]Because of the formatting of your post it's a bit confusing what you're trying to do. Quote Link to comment Share on other sites More sharing options...
mkosmosports Posted January 28, 2007 Author Share Posted January 28, 2007 Yeah, thats the problem though, the ids of each 1st level array are not numeric, so sorting them will not make 0 the first id. They are dates, like 200701, 200611, etc. Array( [200701] => Array ( [1] => France ) [200611] => Array ( [1] => Italy [2] => England ) [200610] => Array ( [1] => England ))So now what I want to do is somehow pull the 200701 out of this md array, and use it in a variable later on. Quote Link to comment Share on other sites More sharing options...
Jessica Posted January 28, 2007 Share Posted January 28, 2007 Those are still numbers. use ksort(), then foreach to go through and get the last one.ksort($arr);foreach($arr AS $k=>$v){$key = $k;}print $k. Quote Link to comment Share on other sites More sharing options...
mkosmosports Posted January 29, 2007 Author Share Posted January 29, 2007 Thanks Jesirose! That loop does it. The query I had was ordered already so I didnt need to make use of ksort. Another array question for y'all. Can I merge/combine two arrays together (ok, I know I can use array_merge, but....), WHILE throwing out any duplicates so I come out with an array only containing all unique values in the other two arrays combined...Thanks... Quote Link to comment Share on other sites More sharing options...
Jessica Posted January 29, 2007 Share Posted January 29, 2007 look through the array functions. Perhaps array_merge then array_unique? Quote Link to comment Share on other sites More sharing options...
mkosmosports Posted January 29, 2007 Author Share Posted January 29, 2007 Damnit, I still cant get a certain syntax right. The following md array:Array( [Griffin] => Array ( [0] => Peter [1] => Lois [2] => Megan [3] => Glenn ) [Quagmire] => Array ( [0] => Glenn ) [Brown] => Array ( [0] => Cleveland [1] => Loretta [2] => Junior ))How can I get all the last names(1st level array id's) when the first name (2nd level array) is Glenn?Thanks! Quote Link to comment Share on other sites More sharing options...
mkosmosports Posted January 29, 2007 Author Share Posted January 29, 2007 Ahhh..I got it folks, nevermind my last post. The solution is:foreach ($arr as $value => $k){ foreach ($k as $key) { if ($key == "Glenn") { echo "$value;<br />\n"; } }}This has given me all the last names when first name is Glenn.. 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.