From f30786d7280451409ac536d3498f351fa153c715 Mon Sep 17 00:00:00 2001 From: Gabor Hojtsy Date: Fri, 28 Dec 2001 18:46:53 +0000 Subject: [PATCH] Eliminate all stuff from CDATA sections, and moved DEV comments out of example code. The manual pages with these examples were a huge mess... git-svn-id: https://svn.php.net/repository/phpdoc/en/trunk@66335 c90b9560-bf6c-de11-be94-00142212c4b1 --- language/types.xml | 97 ++++++++++++++++++++++++++-------------------- 1 file changed, 56 insertions(+), 41 deletions(-) diff --git a/language/types.xml b/language/types.xml index 310b70c2cb..d65998e70e 100644 --- a/language/types.xml +++ b/language/types.xml @@ -1,5 +1,5 @@ - + Types @@ -172,12 +172,13 @@ $foo = True; // assign the value TRUE to $foo operator which returns a boolean +// == is an operator which returns a boolean +if ($action == "show_version") { echo "The version is 1.23"; } // this is not necessary: -if ($show_separators == true) { +if ($show_separators == TRUE) { echo "
\n"; } @@ -833,20 +834,22 @@ echo "He drunk some ${beer}s"; // works 'red' , 'banana' => 'yellow' ); -echo "A banana is $fruits[banana]."; // note that this works differently -outside string-quotes. See $foo[bar] outside strings -echo "This square is $square->width meters broad."; -echo "This square is $square->width00 centimeters broad."; // won't work, - // for a solution, see the complex syntax. +// note that this works differently outside string-quotes. +echo "A banana is $fruits[banana]."; + +echo "This square is $square->width meters broad."; + +// Won't work. For a solution, see the complex syntax. +echo "This square is $square->width00 centimeters broad."; + +]]> -]]>
@@ -876,19 +879,21 @@ echo "This is { $great}"; // won't work, outputs: This is { fantastic} echo "This is {$great}"; // works, outputs: This is fantastic echo "This square is {$square->width}00 centimeters broad."; echo "This works: {$arr[4][3]}"; -echo "This is wrong: {$arr[foo][3]}"; // for the same reason - // as $foo[bar] is wrong outside a string. + +// This is wrong for the same reason +// as $foo[bar] is wrong outside a string. +echo "This is wrong: {$arr[foo][3]}"; + echo "You should do it this way: {$arr['foo'][3]}"; echo "You can even write {$obj->values[3]->name}"; echo "This is the value of the var named $name: {${$name}}"; - -]]> + --> @@ -911,10 +916,10 @@ echo "I'd like to have another {${ strrev('reeb') }}, hips"; Some string examples - + 12 // the value 10 will be overwritten by 12 ); +// empty array +$empty = array(); +]]> - -// empty array -$empty = array(); -]]> @@ -1412,14 +1416,15 @@ Do you like yellow? Collection -foreach ( $colors as $key => $color ) { + $color) { // won't work: - //$color = strtoupper($color); + //$color = strtoupper($color); //works: - $colors[$key] = strtoupper($color); + $colors[$key] = strtoupper($color); } -print_r($colors); +print_r($colors); /* output: Array @@ -1430,6 +1435,7 @@ Array [3] => YELLOW ) */ +]]> @@ -1438,8 +1444,9 @@ Array One-based index + 'January', 'February', 'March'); -print_r($firstquarter); +print_r($firstquarter); /* output: Array @@ -1448,20 +1455,23 @@ Array [2] => 'February' [3] => 'March' ) -*/ +*/ +]]> Filling real array -// fill an array with all items from a directory -$handle = opendir('.'); -while ($file = readdir($handle)) +closedir($handle); +closedir($handle); +]]> @@ -1472,8 +1482,10 @@ while ($file = readdir($handle)) Sorting array -sort($files); -print_r($files); + @@ -1484,23 +1496,24 @@ while ($file = readdir($handle)) Recursive and multi-dimensional arrays -$fruits = array ( "fruits" => array ( "a" => "orange" - , "b" => "banana" - , "c" => "apple" + array ( "a" => "orange" + , "b" => "banana" + , "c" => "apple" ) - , "numbers" => array ( 1 + , "numbers" => array ( 1 , 2 , 3 , 4 , 5 , 6 ) - , "holes" => array ( "first" - , 5 => "second" + , "holes" => array ( "first" + , 5 => "second" , "third" ) ); - +]]>