SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    Wibblesticks Gryff's Avatar
    Join Date
    Oct 2001
    Location
    Asgard
    Posts
    442
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Comparing Array Values

    PHP Code:
    $info = array( "username""fn""ln""mail""mailcheck""age""gender""cc""job" );
            
    $infocheck array_walk$info'htmlspecialchars');
            
    $infocheck array_walk($infocheck'stripslashes'); 

    Is there anyway I can compare all the values of $info against all the values of $infocheck and return true/false, or get any output?
    I know I can always compare all the elements but i'm sure there has to be a better way of doing things.

  2. #2
    gingham dress, army boots... silver trophy redux's Avatar
    Join Date
    Apr 2002
    Location
    Salford / Manchester / UK
    Posts
    4,838
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    re·dux (adj.): brought back; returned. used postpositively
    [latin : re-, re- + dux, leader; see duke.]
    WaSP Accessibility Task Force Member
    splintered.co.uk | photographia.co.uk | redux.deviantart.com

  3. #3
    Wibblesticks Gryff's Avatar
    Join Date
    Oct 2001
    Location
    Asgard
    Posts
    442
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    dunno
    I did see that and it says


    array_diff() returns an array containing all the values of array1 that are not present in any of the other arguments.


    but I suppose I could use $arraydif = array_dif( $info, $infocheck )
    and then use if(!$arraydif)
    I'll have a play and see if it works.

  4. #4
    gingham dress, army boots... silver trophy redux's Avatar
    Join Date
    Apr 2002
    Location
    Salford / Manchester / UK
    Posts
    4,838
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    sorry, i should have explained it a bit more thoroughly...but that's pretty much what i had in mind...
    re·dux (adj.): brought back; returned. used postpositively
    [latin : re-, re- + dux, leader; see duke.]
    WaSP Accessibility Task Force Member
    splintered.co.uk | photographia.co.uk | redux.deviantart.com

  5. #5
    Wibblesticks Gryff's Avatar
    Join Date
    Oct 2001
    Location
    Asgard
    Posts
    442
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    OK! we have this sorted!



    <?
    $array1 = array( "a" => "moo", "sheep");
    $array2 = array( "a" => "moo", "horse");
    $array3 = array_diff($array1, $array2);
    echo("$array3[0]");
    ?>



    that will return sheep
    so I can use if(!array3[0]){
    do stuff;
    }

    I have tested that and it does work
    my only question is why the "a" => and "b" => need to be there for it to work?
    ideas anyone?

  6. #6
    gingham dress, army boots... silver trophy redux's Avatar
    Join Date
    Apr 2002
    Location
    Salford / Manchester / UK
    Posts
    4,838
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    i don't understand it either (i'm not too hot on arrays), but this worked w/out the =>

    PHP Code:
    <?php
    $array1 
    = array("moo""sheep"); 
    $array2 = array("moo""horse"); 
    $array3 array_diff($array1$array2); 
    echo(
    "$array3[1]"); // 1, not 0
    ?>
    magic...
    re·dux (adj.): brought back; returned. used postpositively
    [latin : re-, re- + dux, leader; see duke.]
    WaSP Accessibility Task Force Member
    splintered.co.uk | photographia.co.uk | redux.deviantart.com


Bookmarks

Posting Permissions

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