Difference between revisions of "PHP 3"
From Ilianko
| Line 60: | Line 60: | ||
=== рекурсия=== | === рекурсия=== | ||
| + | <code><pre> | ||
| + | $myArray = array( 1, | ||
| + | array( 2, | ||
| + | 3, | ||
| + | 4 ), | ||
| + | 'five', | ||
| + | array( 'six', | ||
| + | '7', | ||
| + | array('third array', | ||
| + | 'third array second element'))); | ||
| − | function | + | function listArray($array, $step=0) { |
| − | + | if( is_array($array)){ | |
| − | + | foreach($array as $key => $value){ | |
| − | + | echo 'Array index: '.$key; | |
| + | listArray($value); | ||
| + | } | ||
| + | } | ||
| + | else | ||
| + | echo " value $array <br />"; | ||
} | } | ||
| − | + | listArray($myArray) | |
| + | </pre></code> | ||
=== scope === | === scope === | ||
Revision as of 13:22, 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, $step=0) {
if( is_array($array)){
foreach($array as $key => $value){
echo 'Array index: '.$key;
listArray($value);
}
}
else
echo " value $array <br />";
}
listArray($myArray)