13.09.2016 Views

PHP and MySQL Web Development 4th Ed-tqw-_darksiderg

Create successful ePaper yourself

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

40 Chapter 1 <strong>PHP</strong> Crash Course<br />

Or, equivalently on a Windows server, you can use<br />

$out = `dir c:`;<br />

echo ‘’.$out.’’;<br />

Either version obtains a directory listing <strong>and</strong> stores it in $out. It can then be echoed to<br />

the browser or dealt with in any other way.<br />

There are other ways of executing comm<strong>and</strong>s on the server.We cover them in<br />

Chapter 19,“Interacting with the File System <strong>and</strong> the Server.”<br />

Array Operators<br />

There are a number of array operators.The array element operators ([]) enable you to<br />

access array elements.You can also use the => operator in some array contexts.These<br />

operators are covered in Chapter 3.<br />

You also have access to a number of other array operators.We cover them in detail in<br />

Chapter 3 as well, but we included them here in Table 1.6 for completeness.<br />

Table 1.6 <strong>PHP</strong>’s Array Operators<br />

Operator Name Use Result<br />

+ Union $a + $b Returns an array containing everything in $a<br />

<strong>and</strong> $b<br />

== Equality $a == $b Returns true if $a <strong>and</strong> $b have the same<br />

key <strong>and</strong> pairs<br />

=== Identity $a === $b Returns true if $a <strong>and</strong> $b have the same<br />

key <strong>and</strong> value pairs the same order<br />

!= Inequality $a != $b Returns true if $a <strong>and</strong> $b are not equal<br />

Inequality $a $b Returns true if $a <strong>and</strong> $b are not equal<br />

!== Non-identity $a !== $b Returns true if $a <strong>and</strong> $b are not identical<br />

You will notice that the array operators in Table 1.6 all have equivalent operators that<br />

work on scalar variables. As long as you remember that + performs addition on scalar<br />

types <strong>and</strong> union on arrays—even if you have no interest in the set arithmetic behind that<br />

behavior—the behaviors should make sense.You cannot usefully compare arrays to scalar<br />

types.<br />

The Type Operator<br />

There is one type operator: instanceof.This operator is used in object-oriented programming,<br />

but we mention it here for completeness. (Object-oriented programming is<br />

covered in Chapter 6.)

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

Saved successfully!

Ooh no, something went wrong!