Hallo,
Ik heb daarstraks mijn eerste functie geschreven.
Ik wist al lang hoe het moest en nu weet ik hoe makkelijk het is om hem in een funtie te zetten.
Ik zal jullie de beide versies geven van het script.
De functie is: Hoeveel punten je hebt zet hij om in hoeveel geld je al hebt. Bij deze functie is 1 punt 1 cent.
Hier het script wat ik eerst had gemaakt:
Hier heb je hem in functie vorm:
Tips,reaties en opbouwende kritiek mag altijd
Ik heb daarstraks mijn eerste functie geschreven.
Ik wist al lang hoe het moest en nu weet ik hoe makkelijk het is om hem in een funtie te zetten.
Ik zal jullie de beide versies geven van het script.
De functie is: Hoeveel punten je hebt zet hij om in hoeveel geld je al hebt. Bij deze functie is 1 punt 1 cent.
Hier het script wat ik eerst had gemaakt:
[COLOR= #0000BB]<?php
$punten[/COLOR] [COLOR= #007700]=[/COLOR] [COLOR= #DD0000]70,40[/COLOR][COLOR= #007700];[/COLOR] [COLOR= #FF8000]//Aantal punten[/COLOR]
[COLOR= #0000BB]$puntenf[/COLOR] [COLOR= #007700]=[/COLOR] [URL="http://www.php.net/str_replace"]str_replace[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000],[/COLOR][COLOR= #007700],[/COLOR][COLOR= #DD0000].[/COLOR][COLOR= #007700],[/COLOR] [COLOR= #0000BB]$punten[/COLOR][COLOR= #007700]);[/COLOR] [COLOR= #FF8000]//Vervang de komma naar een punt[/COLOR]
[COLOR= #0000BB]$punten_rond[/COLOR] [COLOR= #007700]=[/COLOR] [URL="http://www.php.net/round"]round[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$puntenf[/COLOR][COLOR= #007700]);[/COLOR][COLOR= #FF8000]//Afronden naar een geheel[/COLOR]
[COLOR= #0000BB]$punten_geld[/COLOR] [COLOR= #007700]=[/COLOR] [COLOR= #0000BB]$punten_rond[/COLOR] / [COLOR= #0000BB]100[/COLOR][COLOR= #007700];[/COLOR] [COLOR= #FF8000]//Delen door 100 om er een bedrag van kunnen te maken[/COLOR]
[COLOR= #0000BB]$punten_geld_deci[/COLOR] [COLOR= #007700]=[/COLOR] [URL="http://www.php.net/number_format"]number_format[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$punten_geld[/COLOR][COLOR= #007700],[/COLOR] [COLOR= #0000BB]2[/COLOR][COLOR= #007700],[/COLOR][COLOR= #DD0000],[/COLOR][COLOR= #007700],[/COLOR][COLOR= #DD0000] [/COLOR][COLOR= #007700]);[/COLOR] [COLOR= #FF8000]//2 decimalen als het een tiental cent is.[/COLOR]
[URL="http://www.php.net/echo"]echo[/URL] [COLOR= #DD0000]Je hebt [/COLOR][COLOR= #007700].[/COLOR][COLOR= #0000BB]$punten[/COLOR][COLOR= #007700].[/COLOR][COLOR= #DD0000] punten, dat is gelijk aan [/COLOR][COLOR= #007700].[/COLOR][COLOR= #0000BB]$punten_geld_deci[/COLOR][COLOR= #007700].[/COLOR][COLOR= #DD0000] euro[/COLOR][COLOR= #007700];[/COLOR]
?> Hier heb je hem in functie vorm:
[COLOR= #0000BB]<?php[/COLOR]
[COLOR= #007700]function[/COLOR] puntnaareuro[COLOR= #007700]([/COLOR][COLOR= #0000BB]$punten[/COLOR][COLOR= #007700])
{[/COLOR]
[COLOR= #0000BB]$puntenf[/COLOR] [COLOR= #007700]=[/COLOR] [URL="http://www.php.net/str_replace"]str_replace[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000],[/COLOR][COLOR= #007700],[/COLOR][COLOR= #DD0000].[/COLOR][COLOR= #007700],[/COLOR] [COLOR= #0000BB]$punten[/COLOR][COLOR= #007700]);[/COLOR] [COLOR= #FF8000]//VErvang , => .[/COLOR]
[COLOR= #0000BB]$punten_rond[/COLOR] [COLOR= #007700]=[/COLOR] [URL="http://www.php.net/round"]round[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$puntenf[/COLOR][COLOR= #007700]);[/COLOR][COLOR= #FF8000]//Afronden naar een geheel[/COLOR]
[COLOR= #0000BB]$punten_geld[/COLOR] [COLOR= #007700]=[/COLOR] [COLOR= #0000BB]$punten_rond[/COLOR] / [COLOR= #0000BB]100[/COLOR][COLOR= #007700];[/COLOR] [COLOR= #FF8000]//Delen door 100 om er een bedrag van kunnen te maken[/COLOR]
[COLOR= #0000BB]$punten_geld_deci[/COLOR] [COLOR= #007700]=[/COLOR] [URL="http://www.php.net/number_format"]number_format[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$punten_geld[/COLOR][COLOR= #007700],[/COLOR] [COLOR= #0000BB]2[/COLOR][COLOR= #007700],[/COLOR][COLOR= #DD0000],[/COLOR][COLOR= #007700],[/COLOR][COLOR= #DD0000] [/COLOR][COLOR= #007700]);[/COLOR] [COLOR= #FF8000]//2 decimalen als het een tiental cent is.[/COLOR]
[URL="http://www.php.net/return"]return[/URL] [COLOR= #0000BB]$punten_geld_deci[/COLOR][COLOR= #007700];
}[/COLOR]
?> Tips,reaties en opbouwende kritiek mag altijd

Bedankt