php question - How does the ".=" operator function?

1 reply [Last post]
mcgillrob
Offline
Last seen: 9 years 23 weeks ago
Joined: 2012-10-29

How does the ".=" operator function?

mcgillrob
Offline
Last seen: 9 years 23 weeks ago
Joined: 2012-10-29
The line of code which

The line of code which brought on confusion is as follows:

// 3. A practical function to roll dice.
function roll_dice($highest_number = 6, $num_dice = 1) {
$output = '';
for($i = 0; $i < $num_dice; $i++) {
$number = rand(1, $highest_number);
$output .= ' [' . $number . '] ';
}
$output = 'The result of your roll was: ' . $output;
return $output;
}

the $output variable including the $output variable within it is what confused me however its a rather simple function of appendage. Below is from an explanation I received from irc that will provide a better explanation than I can.

Jobe how about an example
14:12 Jobe $a = "Hello ";
14:12 Jobe $a now contains "Hello "
14:12 Jobe $a = $a . "world";
14:12 Jobe $a now contains "Hello world"
14:13 Jobe this:
14:13 Jobe $a = $a . "world";
14:13 Jobe can also be written as:
14:13 Jobe $a .= "world";
14:13 RobMcGill so its appending the additional data onto the existing variable?
14:13 Jobe yes
14:14 Jobe there are numerous "=" assignment operators
14:14 Hercule to a string infact
14:14 Jobe including but not limited to "/=", "+=", "-=", "*=" etc...
14:14 Jobe they can all be expanded in the same way "$a .= "world";" can be to "$a = $a . "world";"
14:15 Jobe for example
14:15 Jobe say you do:
14:15 Jobe $a = 5;
14:15 Jobe then did:
14:15 Jobe $a += 5;
14:15 Jobe $a would then contain 10

Add to playlist

Add to , or

Add to new playlist:

Add to playlist
This is a member-only feature
But, it's easy to become a member

Add to cart:


Loading...
Contact us

Below are the supported keyboard shortcuts for our video player.

space
Start / stop video
shift
Go to next video
shift
Go to previous video
Increase or decrease player speed by 20%
Skip ahead or go back by 15 seconds
1...9
Jump to a percentage (2 is 20%, for example)
f
Toggle full screen
Videos Pricing More Search
BuildAModule Logo Icon BuildAModule Logo Icon
Become a member!
$29
1 month
$156
6 months
10% off
$276
12 months
20% off
All memberships come with the following:
24 / 7 access to the entire 1800+ video library
An innovative video player with a rolling transcript
Extensive Drupal and cross-platform training
A thorough and thoughtful training style
Progress tracking
Take notes on specific video sections
Intuitive multi-user management
How many users?
user
Go solo with a single user, or give multiple team members access through one account and get discounts by bundling multiple users into a single membership.