---
title: "Spara värdet efter funktionen"
type: "forum-thread"
url: "https://www.webforum.nu/amne/php/44007-spara-värdet-efter-funktionen"
topic: "PHP"
topic_url: "https://www.webforum.nu/amne/php"
author: "Asterix"
published: "2002-05-17T18:59:13.000Z"
updated: "2002-05-18T11:16:46.000Z"
replies: 4
views: 202
page: 1
pages: 1
language: "sv-SE"
site: "webForum — webforum.nu"
rights: "Upphovsrätten till varje inlägg tillhör dess författare."
attribution: "Citera som: webForum, https://www.webforum.nu/amne/php/44007-spara-värdet-efter-funktionen"
---

# Spara värdet efter funktionen

## #1 — Asterix, 2002-05-17T18:59Z

Jag har detta:

```php
funtion temp ($a, $b) {
  $a = 34 + $b;
  $b = $a - 2;
}

$sa = 2;
$sb = 3;

function ($sa, $sb);

echo "$sa, sb";
```

Nu är det så att jag vill att $sa och $sb ska få de värden som de ändras till i funktionen. Hur gör jag det?

Permalänk: https://www.webforum.nu/p/44007

## #2 — Peloquin, 2002-05-17T19:24Z

Testa den här koden:

```php
<?
function temp ($a, $b)
{
  $a = 34 + $b;
  $b = $a - 2;
  echo "$a, $b";
}
$a = 2;
$b = 3;
temp($a, $b);
?>
```

Permalänk: https://www.webforum.nu/p/675065

## #3 — Matte, 2002-05-17T19:33Z

Eller den här:

```php
<?php
function temp ($a, $b) {
  global $a,$b;
  $a = 34 + $b;
  $b = $a - 2;
}

$a = 2;
$b = 3;
temp($a, $b);

echo "$a, $b";
?>
```

\[redigerat\]
Behöver ju knappast skicka in variabler i funktionen:

```php
<?php
function temp () {
  global $a,$b;
  $a = 34 + $b;
  $b = $a - 2;
}

$a = 2;
$b = 3;
temp();

echo "$a, $b";
?>
```

Permalänk: https://www.webforum.nu/p/675068

## #4 — juventus1, 2002-05-17T20:12Z

Eller med referenser:

```php
funtion temp (&$a, &$b) {
  $a = 34 + $b;
  $b = $a - 2;
}

$sa = 2;
$sb = 3;

function ($sa, $sb);

echo "$sa, sb";
```

Permalänk: https://www.webforum.nu/p/675079

## #5 — Asterix, 2002-05-18T11:16Z

Tack för alla svar. Referenser var det jag letade efter eftersom de variabler jag skickar till funktionen heter olika saker.

Permalänk: https://www.webforum.nu/p/678477

---

Tråden på webben: https://www.webforum.nu/amne/php/44007-spara-värdet-efter-funktionen
