How to Convert a Positive Number to Negative in PHP Using Multiplication

This article explains how to convert a positive integer to a negative one in PHP by using either the multiplication operator (*) or the multiplication‑assignment operator (*=), and provides clear code examples for both methods.

php Courses
php Courses
php Courses
How to Convert a Positive Number to Negative in PHP Using Multiplication

In PHP, you can turn a positive number into a negative one by multiplying it by -1.

There are two ways to perform this multiplication: using the * operator or the multiplication‑assignment operator *=.

Method 1 – using the * operator : multiply the variable by -1 directly.

<?php
header("Content-type:text/html;charset=utf-8");
$number = 99;
echo "原正数:" . $number . "<br>";
$number = $number * (-1);
echo "转换后的负数:" . $number; // 输出 -99
?>

Method 2 – using the *= operator : the operator performs the multiplication and assigns the result back to the variable.

<?php
header("Content-type:text/html;charset=utf-8");
$number = 88;
echo "原正数:" . $number . "<br>";
$number *= -1;
echo "转换后的负数:" . $number; // 输出 -88
?>
Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

BackendTutorialmultiplicationnegative-number
php Courses
Written by

php Courses

php中文网's platform for the latest courses and technical articles, helping PHP learners advance quickly.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.