Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"$count{$current}" how this code will be interpreted in php?

Tags:

php

I just saw a piece of php code. I couldn't find an explanation how the interpretor will evaluate this statement $newstring .= "$count{$current}";.

$string = "111221";

for($i = 0; $i < strlen($string); $i++) {

$current = $string[$i];
$count = 1;

while(isset($string[$i + $count]) && ($string[$i + $count] == $current)) $count++;
$newstring .= "$count{$current}";

$i += $count-1;
}

print $newstring;

Anybody please explain this line "$count{$current}". I imagine the doubles quotes is for typecasting to string. But, $count and $current should be numbers. Then what will be the meaning of the curly braces?

like image 478
Abhijith Sasikumar Avatar asked Dec 05 '25 10:12

Abhijith Sasikumar


1 Answers

$newstring .= "$count{$current}";

is the same for

$newstring .= $count . $current;
like image 127
Maksim Tikhonov Avatar answered Dec 09 '25 01:12

Maksim Tikhonov



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!