how += in loops

hello
15 Replies
NIMA
NIMAOP4mo ago
for($i = 0 ; $i < $first_loop_len ; $i++){
$star_1 = "*" ;
echo $star_1; ;

}
for($i = 0 ; $i < $first_loop_len ; $i++){
$star_1 = "*" ;
echo $star_1; ;

}
why when i put echo in loop it will show 8 start and when i put echo outside loop it show only 1 star in javascript for fix the issue i do $star_1 += "*" ; but in php i cant is there any way i get like 8 start every time i call it ? not only 1
ἔρως
ἔρως4mo ago
because you can't increment an asterisk by an asterisk
NIMA
NIMAOP4mo ago
hmm
ἔρως
ἔρως4mo ago
you probably want to do $star .= '*'
NIMA
NIMAOP4mo ago
$star += '*'
ἔρως
ἔρως4mo ago
but what you REALLY want is str_repeat('*', 8)
NIMA
NIMAOP4mo ago
oh i dont need make for loop for this ? is this bulid in func ?
ἔρως
ἔρως4mo ago
yes
NIMA
NIMAOP4mo ago
oh nice is this also in js ?
ἔρως
ἔρως4mo ago
this doesn't work because it is the same as $star = (int)$star + (int)'*' which makes no sense https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/repeat <-- '*'.repeat(8)
NIMA
NIMAOP4mo ago
tnx for help
ἔρως
ἔρως4mo ago
you're welcome in php, you want to do $star .= '*', by the way
NIMA
NIMAOP4mo ago
,
ἔρως
ἔρως4mo ago
the . is used to concatenate strings, meaning that it is the same as this: $star = $star . '*'
NIMA
NIMAOP4mo ago
ohh
Want results from more Discord servers?
Add your server