25.09.2014 Views

ZEND PHP 5 Certification STUDY GUIDE

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Web Programming ” 101<br />

<br />

Perl<br />

<br />

<br />

<br />

Ruby<br />

<br />

<br />

<br />

<br />

<br />

The form above has three checkboxes, all named languages[]; these will all be added<br />

individually to an array called languages in the $_POST superglobal array—just like<br />

when you use an empty key (e.g. $array[] = “foo”) to append a new element to an<br />

existing array in <strong>PHP</strong>. Once inside your script, you will be able to access these values<br />

as follows:<br />

foreach ($_POST[’languages’] as $language) {<br />

switch ($language) {<br />

case ’<strong>PHP</strong>’ :<br />

echo "<strong>PHP</strong>? Awesome! ";<br />

break;<br />

case ’Perl’ :<br />

echo "Perl? Ew. Just Ew. ";<br />

break;<br />

case ’Ruby’ :<br />

echo "Ruby? Can you say... ’bandwagon?’ ";<br />

break;<br />

default:<br />

echo "Unknown language!";<br />

}<br />

}<br />

Licensed to 482634 - Amber Barrow (itsadmin@deakin.edu.au)<br />

When You Don’t Know How Data Is Sent<br />

If you need to write a script that is supposed to work just as well with both GET and<br />

POST requests, you can use the $_REQUEST superglobal array; the latter is filled in<br />

using data from different sources in an order specified by a setting in your php.ini

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

Saved successfully!

Ooh no, something went wrong!