Autor Beitrag
Marco D.
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 2750

Windows Vista
Delphi 7, Delphi 2005 PE, PHP 4 + 5 (Notepad++), Java (Eclipse), XML, XML Schema, ABAP, ABAP OO
BeitragVerfasst: Mi 23.08.06 21:03 
ausblenden Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
$s = array();
$d = array();
$s[0]=1;
$d[0]=1;

function FillArray($count) {
  if ($count > 1) {
    $i = 0;
                echo $s[0];
    while ($i <= $count) {
        $s[$i+1] = $s[$i] + $d[$i];
        $d[i+1] = $d[$i] + (2 * $s[i]);
        $i++;
    }
  }
}

Warum ist $s[0] hier auf einmal leer? :shock: Ist das Array in der function unbekannt? Wie kann man das Problem lösen, da nichts ausgegeben wird. In meinen PHP-Buch wird die globals-Anweisng erwähnt, aber wie kann man die bei einem Array anwenden?

_________________
Pascal keeps your hand tied. C gives you enough rope to hang yourself. C++ gives you enough rope to shoot yourself in the foot


Zuletzt bearbeitet von Marco D. am Mi 23.08.06 21:10, insgesamt 1-mal bearbeitet
Horschdware
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 744
Erhaltene Danke: 54

Win XP Pro, Win 7 Pro x64
Delphi 7, Delphi XE, C++ Builder 5, SAP R/3
BeitragVerfasst: Mi 23.08.06 21:09 
Du musst der Funktion das Array auf irgendeine Art und Weise bekanntmachen.

Z.B. so:
ausblenden Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
$s = array();
$d = array();
$s[0]=1;
$d[0]=1;

function FillArray($count) {
  global $s, $d;
  if ($count > 1) {
    $i = 0;
                echo $s[0];
    while ($i <= $count) {
        $s[$i+1] = $s[$i] + $d[$i];
        $d[i+1] = $d[$i] + (2 * $s[i]);
        $i++;
    }
  }
}



btw: wo bekommst du $count her?

_________________
Delphi: XE - OS: Windows 7 Professional x64
Marco D. Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 2750

Windows Vista
Delphi 7, Delphi 2005 PE, PHP 4 + 5 (Notepad++), Java (Eclipse), XML, XML Schema, ABAP, ABAP OO
BeitragVerfasst: Mi 23.08.06 21:12 
Danke! :zustimm:

_________________
Pascal keeps your hand tied. C gives you enough rope to hang yourself. C++ gives you enough rope to shoot yourself in the foot
mkinzler
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 4106
Erhaltene Danke: 13


Delphi 2010 Pro; Delphi.Prism 2011 pro
BeitragVerfasst: Mi 23.08.06 21:14 
Zitat:
Warum ist $s[0] hier auf einmal leer? :shock: Ist das Array in der function unbekannt?
Ja
Zitat:
Wie kann man das Problem lösen, da nichts ausgegeben wird.
Den array als parameter übergeben oder als global deklarieren. (1. würde ich bevorzugen)

_________________
Markus Kinzler.
UGrohne
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Veteran
Beiträge: 5502
Erhaltene Danke: 220

Windows 8 , Server 2012
D7 Pro, VS.NET 2012 (C#)
BeitragVerfasst: Do 24.08.06 06:45 
Hast Du das in einer eigenen Klasse deklariert? Dann würde ich mal
echo $this->s[0]; versuchen.

Wenns nicht geht, bitte nicht schlagen, programmiere erst seit kurzem mit PHP ;)