11.07.2015 Views

PHP MySQL - Stilson.net

PHP MySQL - Stilson.net

PHP MySQL - Stilson.net

SHOW MORE
SHOW LESS
  • No tags were found...

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

www.it-ebooks.infoCHAPTER 5 • ARRAYSKeyword 3:Keyword 4:Keyword 5:Keyword 6:This form information is then sent to some script, referred to as submitdata.php in the form. Thisscript should sanitize user data and then insert it into a database for later review. Using array_walk(),you can easily filter the keywords using a predefined function:array_walk($_POST['keyword'],"sanitize_data");The result is that each value in the array is run through the strip_tags() function, which results inany HTML and <strong>PHP</strong> tags being deleted from the value. Of course, additional input checking would benecessary, but this should suffice to illustrate the utility of array_walk().■ Note If you’re not familiar with <strong>PHP</strong>’s form-handling capabilities, see Chapter 13.If you’re working with arrays of arrays, the array_walk_recursive() function (introduced in <strong>PHP</strong> 5.0)is capable to recursively apply a user-defined function to every element in an array.Determining Array Size and UniquenessA few functions are available for determining the number of total and unique array values. Thesefunctions are introduced in this section.Determining the Size of an ArrayThe count() function returns the total number of values found in an array. Its prototype follows:integer count(array array [, int mode])117

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!