Jump to content

Array unique problem using php?


Xname

Recommended Posts

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.