Asnexplore
Asnexplore

Reputation: 363

Need to know whats happening in this code exactly

I am little confused with this code

$name = $formData["name"] = stripslashes($mechanic_buy_name);

I found these code being used in one of the script downloaded from internet. I need to know what is it all about?

Also will $name and $formData'["name"] will be having same value and that too with stripslashes.

For example if the value of $mechanic_buy_name = "SomeValue'WithQuote's";

What will be assigned to $name and $formData'["name"] in this case?

Curious to know.

Upvotes: 0

Views: 30

Answers (2)

Samuel Cook
Samuel Cook

Reputation: 16828

You are setting two variables to the same value:

$name = $formData["name"] = stripslashes($mechanic_buy_name);

is the same thing as:

$name = stripslashes($mechanic_buy_name);
$formData["name"] = stripslashes($mechanic_buy_name);

The difference is that it works itself backwards:

stripslashes($mechanic_buy_name) is set to $formData["name"] and $formData["name"] is set to $name.

They are two independent variables. If you change one, it will not effect the other.

Upvotes: 1

GGio
GGio

Reputation: 7653

$name = $formData["name"] = stripslashes($mechanic_buy_name);

is same as

$formData['name'] = stripslashes($mechanic_buy_name);
$name = $formData['name'];

explanation:

$name is equal to the value of $formData['name'] where value of $formData['name'] is equal to the value of $mechanic_buy_name

so in your example if:

$mechanic_buy_name = "SomeValue'WithQuote's";
$name = $formData["name"] = stripslashes($mechanic_buy_name);

echo $name . "\n" . $formData["name"];

will print the following:

SomeValue'WithQuote's
SomeValue'WithQuote's

Upvotes: 1

Related Questions