Forum Moderators: coopster

Message Too Old, No Replies

Adding Only Unique Items to An Array

How?

         

inuwolf

7:27 am on Mar 3, 2006 (gmt 0)

10+ Year Member



I've made a small code snippet that adds a new item ($value = $_GET) to an array in a cookie. My main question is in the title of the post, and I have a related one: How do I delete a specific value from the array and shift all the other values down to fill its place? Will this happen on its own? And one more: Using this code I display the array values in descending order;
foreach ($_COOKIE['best'] as $name => $value) {
$best = urlencode($value);
echo //insert code here
}
}

Is there any way to display this in ascending order?

Thanks,

This is not an urgent post for once. :) If there's a good resource out there for semi-beginners like me please let me know.

jatar_k

5:44 pm on Mar 3, 2006 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



are you looking for unique keys or unique values?

arrays will adjust to remove blank elements, though that depends on whether you are using associative or numeris keys. I think for numeric it can/does leave blank values.

you can sort arrays any way you like

what I do when I am looking at what I can do with a specific type, in this case arrays, I go to main page for that section in the manula and read through the descriptions of each function. If there is anything interesting then I read the page for the function

[php.net...]

inuwolf

7:12 pm on Mar 3, 2006 (gmt 0)

10+ Year Member



Unique values, but I solved that using the in_array function. I guess that just leaves the peripheral questions which I can also probably solve.

jatar_k

7:27 pm on Mar 3, 2006 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



since you have time I figured you didn't really need me to explain it all or give a quick code answer

wandering through the functions will probably prove to be very fruitful

there are a ton of sorting functions, they are all a little different and can be used in many different ways so playing around with them and seeing the variations is good.

you also might see some functions that you didn't know were there ;)

for values use in_array and for keys use array_key_exists