php reken problemen (2).

Gestart doorFreestyle2 reacties11 weergaven

3 berichten · pagina 1 van 1

Freestyle

Lid · Topicstarter

Berichten
7.681
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
1. Ik heb een bedrag uit de database. 20. En hoe maak ik daar: 1.20 van??
Alvast bedankt.
(delen door 100)

2. Ik heb 2 functies. 1 rekent de btw uit. En de ander rekent de winst uit. Alleen als ik dan doe:
btw(winst($string))
Dan komt er een raar antwoord uit.
Bij 10 komt er dan bv, 100 uit.
Appart van elkaar werken ze wel.

Code:

[COLOR= #0000BB]<?php[/COLOR]
[COLOR= #007700]function[/COLOR] btw[COLOR= #007700]([/COLOR][COLOR= #0000BB]$omzet[/COLOR][COLOR= #007700]) {[/COLOR]
    [URL="http://www.php.net/echo"]echo[/URL] [COLOR= #0000BB]$omzet[/COLOR][COLOR= #007700]*[/COLOR][COLOR= #0000BB]1.19[/COLOR][COLOR= #007700];
}

function[/COLOR] winst[COLOR= #007700]([/COLOR][COLOR= #0000BB]$winst[/COLOR][COLOR= #007700],[/COLOR][COLOR= #0000BB]$invest[/COLOR][COLOR= #007700]) {[/COLOR]
    [URL="http://www.php.net/echo"]echo[/URL] [COLOR= #0000BB]$invest[/COLOR][COLOR= #007700]-[/COLOR][COLOR= #0000BB]$winst[/COLOR][COLOR= #007700];
}[/COLOR]
?>


Alvast bedankt.
0
Rik

Lid

Berichten
18.393
Reputatie
0
Punten
0,04
Lid sinds
Laatst gezien
Je echot de dingen in de funtie. In feite doe je dus:

echo BTW echo Winst
Omdat de winst 0 is krijg je dan 10 . 0 = 100 wink
Daarom moet je functies over het algemeen ALTIJD dingen laten returnen;

[COLOR= #0000BB]<?php[/COLOR]
[COLOR= #007700]function[/COLOR] btw[COLOR= #007700]([/COLOR][COLOR= #0000BB]$omzet[/COLOR][COLOR= #007700]) {[/COLOR]
    [URL="http://www.php.net/return"]return[/URL] [COLOR= #0000BB]$omzet[/COLOR][COLOR= #007700]*[/COLOR][COLOR= #0000BB]1.19[/COLOR][COLOR= #007700];
}

function[/COLOR] winst[COLOR= #007700]([/COLOR][COLOR= #0000BB]$winst[/COLOR][COLOR= #007700],[/COLOR][COLOR= #0000BB]$invest[/COLOR][COLOR= #007700]) {[/COLOR]
    [URL="http://www.php.net/return"]return[/URL] [COLOR= #0000BB]$invest[/COLOR][COLOR= #007700]-[/COLOR][COLOR= #0000BB]$winst[/COLOR][COLOR= #007700];
}[/COLOR]

[URL="http://www.php.net/echo"]echo[/URL] btw[COLOR= #007700]([/COLOR][COLOR= #0000BB]10[/COLOR][COLOR= #007700]);[/COLOR] [COLOR= #FF8000]// of echo winst(param1,param2);[/COLOR]
?>
0
Freestyle

Lid · Topicstarter

Berichten
7.681
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
Bedankt!
0

Jouw reactie

Deel je idee, stel een vraag of help een ander verder.

Editor laden…

Praat mee met de One2xs-community.

Inloggen om te reageren