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.

CHAPTER 5 • ARRAYSwww.it-ebooks.infoThis returns the following (your output may vary):Array ( [0] => Arizona [1] => Ohio )Shuffling Array ElementsThe shuffle() function randomly reorders an array. Its prototype follows:void shuffle(array input_array)Consider an array containing values representing playing cards:$cards = array("jh", "js", "jd", "jc", "qh", "qs", "qd", "qc","kh", "ks", "kd", "kc", "ah", "as", "ad", "ac");shuffle($cards);print_r($positions);This returns something along the lines of the following (your results will vary because of the shuffle):Array ( [0] => js [1] => ks [2] => kh [3] => jd[4] => ad [5] => qd [6] => qc [7] => ah[8] => kc [9] => qh [10] => kd [11] => as[12] => ac [13] => jc [14] => jh [15] => qs )Adding Array ValuesThe array_sum() function adds all the values of input_array together, returning the final sum. Itsprototype follows:mixed array_sum(array array)If other data types (a string, for example) are found in the array, they will be ignored. An examplefollows:This returns the following:84132

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

Saved successfully!

Ooh no, something went wrong!