SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Wizard gold trophysilver trophy
    Join Date
    Nov 2000
    Location
    Switzerland
    Posts
    2,479
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Wierdness with arrays and string fns

    Wondering if I'm doing something wrong here.

    One of the things I like about php is you can run a function on an array, and it will apply it to every element of the array e.g.

    PHP Code:
    $_GET myFunction $_GET ); 
    That works marvellously most of the time but, certain functions turn every element of the array into the letter A, e.g.

    PHP Code:
    $_GET htmlspecialchars $_GET ); 
    Will turn them all to an A (also found that nl2br, htmlentities, addslashes / stripslashes do the same).

    Thankfully, str_replace works fine.

    Anything I'm doing here or is the bug?

  2. #2
    Wibblesticks Gryff's Avatar
    Join Date
    Oct 2001
    Location
    Asgard
    Posts
    442
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    yeah.
    there is a function for this
    $_GET = array_walk($_GET , 'functionname');
    that should fix your prob.

  3. #3
    SitePoint Wizard gold trophysilver trophy
    Join Date
    Nov 2000
    Location
    Switzerland
    Posts
    2,479
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks

    Phew - many lines saved in writing my own functions.

  4. #4
    Wibblesticks Gryff's Avatar
    Join Date
    Oct 2001
    Location
    Asgard
    Posts
    442
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    your very lucky lol
    I only found that function < 12 hours ago.
    If you check out my post below you'll see why

  5. #5
    SitePoint Wizard silver trophy redemption's Avatar
    Join Date
    Sep 2001
    Location
    Singapore
    Posts
    5,269
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    you guys may also be interested in the array_map(), array_filter() and array_reduce() functions which are like the map, filter and reduce functions used in functional languages to work on lists... specifically array_map which is similar to array_walk


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
  •