PHP docs
| Id/Actions | Category | Code Examples | Test Code | Links | Remarks |
|---|---|---|---|---|---|
| 7 View |
some pseudo-types (mixed) | <?php
// 1. mixed
// gettype() for example will accept all PHP types
$data = array(1, 1., NULL, new stdClass, 'foo');
foreach ($data as $value) {
echo gettype($value), "<br>";
}
echo "<br>";
// str_replace() will accept strings and arrays.
// Provides: <body text='black'>
$bodytag = str_replace("%body%", "black", "body text='%body%'>");
echo $bodytag . "<br><br>";
// Provides: Hll Wrld f PHP
$vowels = array("a", "e", "i", "o", "u", "A", "E", "I", "O", "U");
$onlyconsonants = str_replace($vowels, "", "Hello World of PHP");
print_r($onlyconsonants); echo "<br><br>";
// Provides: You should eat pizza, beer, and ice cream every day
$phrase = "You should eat fruits, vegetables, and fiber every day.";
$healthy = array("fruits", "vegetables", "fiber");
$yummy = array("pizza", "meat", "ice cream");
$newphrase = str_replace($healthy, $yummy, $phrase);
print($newphrase); |
integer double NULL object string body text='black'> Hll Wrld f PHP You should eat pizza, meat, and ice cream every day. |
||
| 8 View |
some pseudo-types for readability reasons | <?php /*** // 2. number number: number indicates that a parameter can be either integer or float. // 3. callback functions: callback: Some functions like call_user_func() or usort() accept user-defined callback functions as a parameter. Callback functions can not only be simple functions, but also object methods, including static class methods. ***/ |
http://www.php.net/manual/en/language.pseudo-types | ||
| 9 View |
type check | <?php
$a_bool = TRUE; // a boolean
$a_str = "foo"; // a string
$a_str2 = 'foo'; // a string
$an_int = 12; // an integer
echo gettype($a_bool) . "<br>"; // prints out: boolean
echo gettype($a_str) . "<br>"; // prints out: string
// If this is an integer, increment it by four
if (is_int($an_int)) {
$an_int += 4;
echo $an_int;
}
// If $a_bool is a string, print it out
// (does not print out anything)
if (is_string($a_bool)) {
echo "String: $a_bool";
}
|
boolean string 16 |
||
| 10 View |
boolean | <?php var_dump((bool) ""); // bool(false) var_dump((bool) 1); // bool(true) var_dump((bool) -2); // bool(true) var_dump((bool) "foo"); // bool(true) var_dump((bool) 2.3e5); // bool(true) var_dump((bool) array(12)); // bool(true) var_dump((bool) array()); // bool(false) var_dump((bool) "false"); // bool(true) |
bool(false) bool(true) bool(true) bool(true) bool(true) bool(true) bool(false) bool(true) | http://www.php.net/manual/en/language.types.boolean.php | |
| 11 View |
integers | <?php $a = 1234; // decimal number $a = -123; // a negative number $a = 0123; // octal number (equivalent to 83 decimal) $a = 0x1A; // hexadecimal number (equivalent to 26 decimal) // converting a float value to integer: $aFloat = 3.14159; echo intval($aFloat); |
3 | http://www.php.net/manual/en/language.types.integer.php |
Page 1 of 10, showing 5 records out of 46 total, starting on record 1, ending on 5
