Difference between revisions of "PHP 3"
From Ilianko
(→scope) |
|||
Line 65: | Line 65: | ||
3, | 3, | ||
4 ), | 4 ), | ||
− | + | 'five', | |
− | + | array( 'six', | |
− | + | '7', | |
− | + | array('third array', | |
'third array second element'))); | 'third array second element'))); | ||
− | function listArray($array | + | function listArray($array) { |
+ | //Array Dump | ||
if( is_array($array)){ | if( is_array($array)){ | ||
foreach($array as $key => $value){ | foreach($array as $key => $value){ |
Latest revision as of 13:35, 20 October 2013
Един код извикваме от много места
над 3500 вградени функции наименование букви и цифри
Contents
Функции
function sumNumbers() { echo 2+2 } sumNumbers();
параметри
function sumNumbers($a,$b) { echo $a+$b; } sumNumbers(2,2);
параметри по подразбиране
function sumNumbers($a) { echo $a+3; } sumNumbers(2);
function sumNumbers($a, $b = 3) { echo $a+$b; } sumNumbers(2); sumNumbers(2,4);
връщане на резултати
function sumNumbers($a, $b=3) { $a = $a + $b; return $a; }
$result = sumNumbers(2); echo $result;
function sumNumbers($a, $b=3) { return $a; echo $a + $b; }
рекурсия
$myArray = array( 1,
array( 2,
3,
4 ),
'five',
array( 'six',
'7',
array('third array',
'third array second element')));
function listArray($array) {
//Array Dump
if( is_array($array)){
foreach($array as $key => $value){
echo 'Array index: '.$key;
listArray($value);
}
}
else
echo " value $array <br />";
}
listArray($myArray)
scope
$a = 3; $b = 4; sumNumbers($a, $b); function sumNumbers($a, $b) { echo $a + $b.'<br />'; $a = 333; echo $a.'<br />'; } echo $a.'<br />';
$a = 3; $b = 4; sumNumbers($a, $b); function sumNumbers(&$a, $b) { echo $a + $b.'<br />'; $a = 333; echo $a.'<br />'; } echo $a.'<br />';