Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    New Coder
    Join Date
    Feb 2007
    Posts
    21
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Cool Changing Duplicate Array Values?

    Hello,

    I need some help trying to change duplicate array values to unique ones. Is there a way to search for all the 'unknown' values in the array and rename them to something unique?


    Code:
    
        [name] => unknown
        [city] => new york
        [zipcode] => unknown
        [region] => east
        [year] => 2007
        [gender] => unknown
        [experience] => unknown
    I would like to rename them to something unique such as 'unknown 01' , 'unknown 02', etc. dynamically without having to know the key name ... Any help is much appreciated!

    ~ Thanks

  • #2
    Regular Coder zro@rtv's Avatar
    Join Date
    Feb 2005
    Location
    on the network
    Posts
    433
    Thanks
    0
    Thanked 1 Time in 1 Post
    PHP Code:
    $i=0;
    foreach (
    $array as $key => $value){
        if (
    $value == "unknown" ){
            
    $array[$key] = "unknown" $i;
            
    $i++;
        }

    dunno if thats the most elegant, but should work.
    Also, not sure how multidimensional yr array is, if its deep obviously there needs to be mod.
    ._-zro
    zro@redtv
    zro.redtv.org

    "If HTML and the Web made all the online documents look like one huge book, RDF, schema, and inference languages will make all the data in the world look like one huge database"
    -Tim Berners-Lee, Weaving the Web, 1999

  • #3
    New Coder
    Join Date
    Feb 2007
    Posts
    21
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Arrow

    Quote Originally Posted by zro@rtv View Post
    PHP Code:
    $i=0;
    foreach (
    $array as $key => $value){
        if (
    $value == "unknown" ){
            
    $array[$key] = "unknown" $i;
            
    $i++;
        }

    dunno if thats the most elegant, but should work.
    Also, not sure how multidimensional yr array is, if its deep obviously there needs to be mod.
    Hi zro,

    I appreciate the response ... one question - my array is named '$output', where do I put that into the code?

    Thanks ~

  • #4
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,994
    Thanks
    4
    Thanked 2,662 Times in 2,631 Posts
    Switch anything you see that says '$array' with '$output' no quotes of course. Unfortunatly, this isn't exactly a unique seeker, it will only replace when it finds the word 'unknown'. Does that still satisfy what you need, because if it does, this will fix it. Otherwise, we'll be looking at a recursion technique to search it...
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 
    Been gone for a few months, and haven't programmed in that long of a time. Meh, I'll wing it ;)

  • #5
    New Coder
    Join Date
    Feb 2007
    Posts
    21
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Smile

    Thanks for the help! ... I really appreciate it. The code works perfectly!

    Regards ~


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •