Welcome Guest, Not a member yet? Register   Sign In
What is .= ?
#1

[eluser]phantom-a[/eluser]
Sorry this may sound real dumb but I cannot find anything on google becuase Google doesn't return results for symbols like "=", so I can't put "what is .= in php" Wink



$var .=


what is that . (dot) beside the equal sign?
#2

[eluser]Hannes Nevalainen[/eluser]
It's a concat of the strings. It's the same as writing:
Code:
$a = $a . $b;
//same as
$a .= $b;
#3

[eluser]Sam Dark[/eluser]
It's equal to $var = $var.
#4

[eluser]phantom-a[/eluser]
Code:
<?php
$output = 'CodeIgniter';
$output .= 'rocks';
echo $output;
?>

Smile
#5

[eluser]xwero[/eluser]
Don't forget the space, you're output is now CodeIgniterrocks Smile
#6

[eluser]NateL[/eluser]
it simply appends, rather than overwrites.

in other words (taking from phantom-a's example)...


Code:
<?php
$output = 'CodeIgniter';
$output .= 'rocks';
echo $output;
?>

the echo $output command would output "CodeIgniterrocks" (literally...since there were no spaces er anything :-) )

However, if you had
$output = 'CodeIgniter';
$output = 'rocks';

it would output "rocks". You're initially setting $output to 'CodeIgniter', and then if you don't put the .=, you are re-setting $output to 'rocks'.

again, .= just appends to what is already there.
#7

[eluser]phantom-a[/eluser]
[quote author="NateL" date="1221077796"]it simply appends, rather than overwrites.

in other words (taking from phantom-a's example)...


Code:
<?php
$output = 'CodeIgniter';
$output .= 'rocks';
echo $output;
?>

the echo $output command would output "CodeIgniterrocks" (literally...since there were no spaces er anything :-) )

However, if you had
$output = 'CodeIgniter';
$output = 'rocks';

it would output "rocks". You're initially setting $output to 'CodeIgniter', and then if you don't put the .=, you are re-setting $output to 'rocks'.

again, .= just appends to what is already there.[/quote]

Yes its very simple, actually the reason I asked yesterday is I was trying to understand what this does but know I fully understand it.


Code:
$output = '<ul>';
           foreach ($query->result() as $function_info) {
                 if ($description) {
                     $output .= '<li><strong>' . $function_info->name . '</strong><br />';
                     $output .= $function_info->function_description . '</li>';
            } else {
                     $output .= '<li>' . $function_info->function_name . '</li>';
            }                    
           $output .= '</ul'>;
           return $output
    } else{
           return '<p>Sorry no results</p>';
   }




Theme © iAndrew 2016 - Forum software by © MyBB