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.

Arrays ” 55<br />

$a = array (’a’, ’b’, ’c’);<br />

var_dump (array_flip ($a));<br />

This outputs:<br />

array(3) {<br />

["a"]=><br />

int(0)<br />

["b"]=><br />

int(1)<br />

["c"]=><br />

int(2)<br />

}<br />

On the other hand, array_reverse() actually inverts the order of the array’s elements,<br />

so that the last one appears first:<br />

$a = array (’x’ => ’a’, 10 => ’b’, ’c’);<br />

var_dump (array_reverse ($a));<br />

Note how key association is only lost for those elements whose keys are numeric:<br />

array(3) {<br />

[0]=><br />

string(1) "c"<br />

[1]=><br />

string(1) "b"<br />

["x"]=><br />

string(1) "a"<br />

}<br />

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

Array Iteration<br />

Iteration is probably one of the most common operations you will perform with arrays—besides<br />

creating them, of course. Unlike what happens in other languages,<br />

where arrays are all enumerative and contiguous, <strong>PHP</strong>’s arrays require a set of functionality<br />

that matches their flexibility, because “normal” looping structures cannot

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

Saved successfully!

Ooh no, something went wrong!