PHP Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsProgrammingPHP Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old January 31st, 2004, 11:31 PM
jdkarns jdkarns is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jan 2004
Location: Dayton, OH
Posts: 12 jdkarns User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
What does the *= do? (PHP question)

What does the *= mean or do?

include ("config.php");
include ("include.php");
include ("lang.php");
session_start();

$c *= 1; // <<<---- What does the *= part of the variable do?
if ($c == 0) { $c = 1; };
$sql = mysql_query("SELECT name, title, description, pages, ref FROM {$prefix}categories WHERE id = $c");
$current_category = mysql_fetch_array($sql, MYSQL_ASSOC);
if (($c > 1) & !$current_category["name"]){
header("Location: {$dir}index.php");
};
if (!$current_category["name"]) { $current_category["name"] = "Directory Search"; };
if (!$current_category["title"]) { $current_category["title"] = $current_category["name"]; };
if (!$current_category["description"]) { $current_category["description"] = $current_category["name"]." ".$current_category["title"]; };
$last_category = false;
$ref = $c;

Last edited by jdkarns : January 31st, 2004 at 11:35 PM. Reason: Change title to say PHP question

Reply With Quote
  #2  
Old February 1st, 2004, 06:59 AM
bbodien bbodien is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Feb 2004
Posts: 7 bbodien User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Send a message via MSN to bbodien
Exclamation

Hello,

*= is an assignment operator to multiply while assigning. Here's an example:

PHP Code:
 $a 5;
$b 2;

$b *= $a;

echo 
$b


The final value of $b is 10, since b*a == 2*5 == 10.

This is the same as doing:

PHP Code:
 $a 5;
$b 2;

$b $b $a


It's just a shortcut. You can also do:
+= (for addition assignment)
-= (for subtraction assignemnt)
/= (for division assignment)

In your code, $c is being multiplied by 1, and the result is being stored back in $c. A bit of a strange thing to do if you ask me, but whatever floats your boat

Hope that helps!

Reply With Quote
  #3  
Old February 2nd, 2004, 10:01 AM
jdkarns jdkarns is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jan 2004
Location: Dayton, OH
Posts: 12 jdkarns User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Thank you very much!

bbodien,

That does help 100%. I have been reading a book called Beggining PHP 4 by wrox. Although it's a good book it stays microscopic in scope so long that you cant see the big picture. I understand what they show in each example of syntax and working with forms etc. at the time. But, it is very difficult to see how to work with all the things they show you (as a whole). Again Thanks alot!

Thank you

Sean Karns

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingPHP Development > What does the *= do? (PHP question)


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway
Stay green...Green IT