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.

52 ” Arrays<br />

}<br />

int(3)<br />

Note how the the resulting array includes all of the elements of the two original arrays,<br />

even though they have the same values; this is a result of the fact that the keys<br />

are different—if the two arrays had common keys (either string or numeric), they<br />

would only appear once in the end result:<br />

$a = array (1, 2, 3);<br />

$b = array (’a’ => 1, 2, 3);<br />

var_dump ($a + $b);<br />

This results in:<br />

array(4) {<br />

[0]=><br />

int(1)<br />

[1]=><br />

int(2)<br />

[2]=><br />

int(3)<br />

["a"]=><br />

int(1)<br />

}<br />

Comparing Arrays<br />

Array-to-array comparison is a relatively rare occurrence, but it can be performed<br />

using another set of operators. Like for other types, the equivalence and identity<br />

operators can be used for this purpose:<br />

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

$a = array (1, 2, 3);<br />

$b = array (1 => 2, 2 => 3, 0 => 1);<br />

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

var_dump ($a == $b); // True<br />

var_dump ($a === $b); // False<br />

var_dump ($a == $c); // False

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

Saved successfully!

Ooh no, something went wrong!