Wrox Programmer Forums
Go Back   Wrox Programmer Forums > PHP/MySQL > Beginning PHP
|
Beginning PHP Beginning-level PHP discussions. More advanced coders should post to the Pro PHP forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Beginning PHP section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old January 14th, 2005, 12:14 PM
Authorized User
 
Join Date: Jan 2005
Posts: 32
Thanks: 0
Thanked 0 Times in 0 Posts
Default What does ($data . =) do in php

i was wondering if anyone could explain what the lines in bold mean. i don't understand what $data . = does

function RandomNumber($length)
{
$Random = srand((double)microtime()*1000000);

$data = "AbcDE123GHIJK4LMN567QRSTU89VWXYZ";
$data .= "aBCdefghijklmn123opq45rs67tuv89wxyz";
$data .= "0FGH45OP89";


for($i = 0; $i < $length; $i++)
{
$Random .= substr($data, (rand()%(strlen($data))), 1);
}
echo "$Random <br>";
}
RandomNumber(8);

Thanks,

Scoobie

 
Old January 14th, 2005, 12:30 PM
Authorized User
 
Join Date: Jan 2005
Posts: 82
Thanks: 0
Thanked 0 Times in 0 Posts
Default

it concatnates the value to the right of the variable name, $data, to the existing value of $data.
e.g.

$data = "first"
echo $data; //(will print: first)
$data .= "second"
echo $data; //will print: firstsecond)
$data .="third"
echo $data; //will print: firstsecondthird)

thats the basic idea. I am pretty sure you can also do

$data = $data + "second" + "third";

to acheive the same thing.


 
Old January 14th, 2005, 04:40 PM
Registered User
 
Join Date: Jan 2005
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Just a small thing, but if you called that RandomNumber() function more than once you would get non-random (predictable) results. Don't call srand() more than once in a script. Ever. Its a very, very bad idea.






Similar Threads
Thread Thread Starter Forum Replies Last Post
Inserting data into MS_ACCESS in PHP lakshmi_annayappa PHP Databases 1 June 25th, 2008 03:38 AM
Passing data from PHP to Javascript oldBroh Javascript How-To 12 June 12th, 2008 11:12 PM
Php transfering data to mysql Gaurava PHP How-To 2 January 5th, 2008 07:33 AM
passing data to php pgm Maureen Beginning PHP 8 October 17th, 2003 03:40 PM
form data not passed to php keng BOOK: Beginning PHP4/PHP 5 ISBN: 978-0-7645-4364-7; v5 ISBN: 978-0-7645-5783-5 2 September 4th, 2003 09:15 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.