Zum Inhalt springen
View in the app

A better way to browse. Learn more.

Fachinformatiker.de

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

PHP Variablen Geltungsbereich vergrößern

Empfohlene Antworten

Veröffentlicht

Hallo zusammen,

1. wie kann ich innerhalb einer funktion eine variable so deklarieren, damit sie im kompletten script bekannt wird?

2. Und wie mache ich das ausserhalb einer funktion?

Gruß,

kills

Original geschrieben von kills

Hallo zusammen,

1. wie kann ich innerhalb einer funktion eine variable so deklarieren, damit sie im kompletten script bekannt wird?

2. Und wie mache ich das ausserhalb einer funktion?

Gruß,

kills

servus!

1. gar ned glaub ich! vielleicht mit "globals" oder so! -->schlechter programmierstil! ;)

2. schon mal an OOP gedacht bei php?? da könntest ja die Attribute verwenden.

Gruß

Azrael

Ganz einfach nur das Schlüsselwort "global" vor die zu nutzende Variable schreiben:



$b=1;
$a=2;

function dummy() {
global $b; //$b bekanntmachen
$a=4;
$b=2;
echo "innerhalb Funktion<br/>\n";
echo "a=$a<br/>\n";
echo "b=$b<br/>\n";
}

echo "a=$a<br/>\n";
echo "b=$b<br/>\n";
dummy();
echo "a=$a<br/>\n";
echo "b=$b<br/>\n";
[/PHP]

Ansonsten, guckst du hier: http://www.html-world.de/program/php_3.php

Original geschrieben von computercrustie

Ganz einfach nur das Schlüsselwort "global" vor die zu nutzende Variable schreiben:



$b=1;
$a=2;

function dummy() {
global $b; //$b bekanntmachen
$a=4;
$b=2;
echo "innerhalb Funktion<br/>\n";
echo "a=$a<br/>\n";
echo "b=$b<br/>\n";
}

echo "a=$a<br/>\n";
echo "b=$b<br/>\n";
dummy();
echo "a=$a<br/>\n";
echo "b=$b<br/>\n";
[/PHP]

Ansonsten, guckst du hier: http://www.html-world.de/program/php_3.php [/b]

das weiss ich ja,

es ging darum eine variable im kompletten script bekannt machen.

ich möchte quasi eine superglobale varible erschaffen.

Archiv

Dieses Thema wurde archiviert und kann nicht mehr beantwortet werden.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.