[PHP] Getal naar sterretjes.

Gestart dooranoniem91734 reacties46 weergaven

5 berichten · pagina 1 van 1

Berichten
994
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
str_replace?
0
Berichten
994
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
Oh, met preg_replace kan het smile
0
Berichten
3.314
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
[COLOR= #0000BB]<?php
$aantal[/COLOR] [COLOR= #007700]=[/COLOR] [COLOR= #DD0000]"10"[/COLOR][COLOR= #007700];[/COLOR]
[URL="http://www.php.net/echo"]echo[/URL] [URL="http://www.php.net/str_replace"]str_replace[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$aantal[/COLOR][COLOR= #007700],[/COLOR] [COLOR= #DD0000]"*"[/COLOR][COLOR= #007700],[/COLOR] [COLOR= #0000BB]$aantal[/COLOR][COLOR= #007700]);[/COLOR]
?>


Op de eerste plek is het aantal een integer, dus die haakjes doen we weg.

[COLOR= #0000BB]<?php
$aantal[/COLOR] [COLOR= #007700]=[/COLOR] [COLOR= #0000BB]10[/COLOR][COLOR= #007700];[/COLOR]
[URL="http://www.php.net/echo"]echo[/URL] [URL="http://www.php.net/str_replace"]str_replace[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$aantal[/COLOR][COLOR= #007700],[/COLOR] [COLOR= #DD0000]"*"[/COLOR][COLOR= #007700],[/COLOR] [COLOR= #0000BB]$aantal[/COLOR][COLOR= #007700]);[/COLOR]
?>


Str_replace is niet nodig, het is geen string.

[COLOR= #0000BB]<?php
$aantal[/COLOR] [COLOR= #007700]=[/COLOR] [COLOR= #0000BB]10[/COLOR][COLOR= #007700];[/COLOR]

[URL="http://www.php.net/while"]while[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$aantal[/COLOR][COLOR= #007700]>[/COLOR][COLOR= #0000BB]0[/COLOR][COLOR= #007700])[/COLOR][COLOR= #FF8000]//zolang aantal meer dan 0 is[/COLOR]
[COLOR= #007700]{[/COLOR]
[URL="http://www.php.net/echo"]echo[/URL] [COLOR= #DD0000]*[/COLOR][COLOR= #007700];[/COLOR]
 [COLOR= #0000BB]$aantal[/COLOR][COLOR= #007700]--;[/COLOR] [COLOR= #FF8000]// eentje ervanaf[/COLOR]
[COLOR= #007700]}[/COLOR]

?>
0
Berichten
3.314
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
np yummie das dan 99999 punten aub (nee grapje)
0
Berichten
3.314
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
LOOL dat was n grapje xD

mr toch 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