Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.


  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint

Lösung

Nutzen Sie array_walk( ):

function escape_data(&$value, $key) {
    $value = htmlentities($value, ENT_QUOTES);
}
$names = array('firstname' => "Baba",
               'lastname'  => "O'Riley");

array_walk($names, 'escape_data');
foreach ($names as $name) {
    print "$name";
}
Baba
O'Riley

Und für geschachtelte Daten array_walk_recursive( ):

function escape_data(&$value, $key) {
    $value = htmlentities($value, ENT_QUOTES);
}
$names = array('firstnames' => array("Baba", "Bill"),
               'lastnames'  => array("O'Riley", "O'Reilly"));
array_walk_recursive($names, 'escape_data');

foreach ($names as $nametypes) {
    foreach ($nametypes as $name) {
        print "$name";
    }
}
Baba
Bill
O'Riley
O'Reilly

  

You are currently reading a PREVIEW of this book.

                                                                                                                    

Get instant access to over $1 million worth of books and videos.

  

Start a Free Trial


  
  • Safari Books Online
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint