Xname Posted May 11, 2012 Share Posted May 11, 2012 Hi,Dear Frnd...........I Hope u r all fine. I am using php array_unique function.Here is the problem in this function. This is the code. <?php $frnd1 = array( 0=> 'arfan', 1=> 'haider', 2=> array( 0=> 'azeem', 1=> 'jeme', ), 3=> array( 0=> 'haider', 1=> 'one' ) ); // please do not change the above code. // You can only change below code. print_r($frnd1); echo '<hr />'; print_r(array_unique($frnd1)); ?> This work fine,But when I am used array_unique then it does not work. When I am used array_unique.It ignore the [3]=>Array. As you can see in my array,Here is two time name "haider". I want to do that in this array all same names are convert into one unique name. In this array I want to ignore the "haider" name bcs it is two time.How can I do that. Remmber :: This example is very simple.Bcs u can understand it easily.Suppose if it is dynamically changed array then what i did do to make it unique. Quote Link to comment Share on other sites More sharing options...
PravinS Posted May 11, 2012 Share Posted May 11, 2012 Its a 2 dimensional array and array_unique does not support 2 dimensional array Quote Link to comment Share on other sites More sharing options...
Psycho Posted May 11, 2012 Share Posted May 11, 2012 Its a 2 dimensional array and array_unique does not support 2 dimensional array pbs is correct. I think a better question is why you have similar data types categorized differently. Why doesn't your original array look like this? $frnd1 = array( 0=> 'arfan', 1=> 'haider', 2=> 'azeem', 3=> 'jeme', 4=> 'haider', 5=> 'one' ) In fact, I have to assume that array is built dynamically, so perhaps the best place to solve this is where the array is created. Quote Link to comment Share on other sites More sharing options...
Xname Posted May 11, 2012 Author Share Posted May 11, 2012 Hi,...........I Hope u r all fine. I know this is 2-dimensional array. But array always built dynamically and I am not able to make it a simple array. Can here is not any code to make it unique. If not, Then how can I changed 2-demensional array in a simple array. Quote Link to comment Share on other sites More sharing options...
Jessica Posted May 11, 2012 Share Posted May 11, 2012 There are at least 3 different user created functions which do this in the comments of array_unique. Quote Link to comment Share on other sites More sharing options...
Psycho Posted May 11, 2012 Share Posted May 11, 2012 I know this is 2-dimensional array. But array always built dynamically and I am not able to make it a simple array. As I stated previously, if you are dynamically building the array, then most likely the place to implement the fix will be where you build the array. Sow that code. Quote Link to comment Share on other sites More sharing options...
Xname Posted May 12, 2012 Author Share Posted May 12, 2012 Sorry,Psycho.I can not show You this code.Security reason. If not any method to make a 2-dem array in unique. Please tell me "NO" or "YES". Quote Link to comment Share on other sites More sharing options...
Jessica Posted May 12, 2012 Share Posted May 12, 2012 There are at least 3 different user created functions which do this in the comments of array_unique. :shrug: Quote Link to comment Share on other sites More sharing options...
Psycho Posted May 12, 2012 Share Posted May 12, 2012 Sorry,Psycho.I can not show You this code.Security reason. If not any method to make a 2-dem array in unique. Please tell me "NO" or "YES". Yes. As for not being able to show the code for "security reasons", that a stupid excuse. You can easily change DB field names, remove DB credentials, etc. in order to show the code that produces the array. jesirose already pointed out that there are examples in the manual to do what you ask on the multi-dimensional array if you want to take that approach which, to me, is the wrong solution. 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.