Jump to content
  • Announcements

    • alpenwasser

      Please Use CODE Tags   31 Jan 2016

      Welcome to the Programming and Software Design Section,

      When asking for help with programming issues, please use the code tags to enclose your code, it makes things much more easily readable for the people trying to help you, thus improving your chances of actually getting help.
        To add code tags, click the <> button on the editor toolbar, then enter your code in the code editor that appears. If you are on a mobile device, or prefer to use BBCode, you can use [code] // Your code here // It will be syntax highlighted, though not necessarily corectly. [/code] (but the code editor is more consistent and less buggy).
bomberblyat

PHP help with $values

15 hours ago, leodaniel said:

Always whats more human (you and me :P) readable.

Name your variables appropriately (having var1-var15 is bad, its hard to understand what they each represent), always step by step so that it's easy to understand.

Just try to make it simple. Imagine you would have to look at your script again in 10 years... how long would you take to understand it (goal is to shorten this time). I think it's important to always code with that in mind. 

 

In the 2. code example it's really hard to understand what the code does, what the variables are. It takes quit some time to understand what it does.

 

i fixed it the code works it was pain in the ass, but it works xD

Recommended Posts

Posted · Original PosterOP

Hi

 

is it possible anyhow to make something like this   ?

  echo $value / $value1 = $value3

basically use php divide output as new value.

 

I appreciate any answers :)

Link to post
Share on other sites
17 minutes ago, bomberblyat said:

Hi

 

is it possible anyhow to make something like this   ?


  echo $value / $value1 = $value3

basically use php divide output as new value.

 

I appreciate any answers :)

4
$value1 = 100;
$value3 = 10;
$value = $value1 / $value3;
echo $value;

 


Make sure to quote me or use @Homeless Pineapple if you want a prompt reply!

I once was a pineapple, young and bold, when my life took an unexpected toll.

 

Desktop - Ryzen RGB

CPU - Ryzen 7 1700 | Motherboard - MSI B350M MORTARRAM - Corsair Vengeance LPX 16GB (2x8GB) DDR4-3200 | GPU - NVIDIA GeForce GTX 1070 FE

Case - Thermaltake Core V21 | Storage - Samsung 960 EVO 500GB, Samsung 850 EVO 120GB, Crucial MX100 128GB, Seagate FireCuda 1TB | PSU - EVGA B3 650W

DisplaysSamsung S24D300H and S22F350 | Keyboard - Corsair K70 LUX RGB | Mouse - SteelSeries Rival 300 | Audio - Bose ST II and QC 25  

 

Laptop - Thinkpad Yoga 370

CPU - Core i5 7300U | Memory - 8GB (1x8gb) DDR4-2133 | Storage - Intel 600p 512GB

 

Smart Devices - Google Pixel with Mobvoi Ticwatch S

Link to post
Share on other sites

If you're just trying to cut down on lines it can be done with

 

$value1 = 100;
$value3 = 10;

echo $value = ($value1 / $value3);
Output -> 10

//Showing that it works to print out the $value
echo $value;
Output -> 10

 


| Intel i5 4670k @ 4.3GHz | XFX RX 480 8 GB | Asus Z87i-Pro | 8.0 GB Kinston DDR3 | Samsung Evo 120GB SSD |

Link to post
Share on other sites
Posted · Original PosterOP
<html>
<body>
<?php     $value1 = 500;
			$value2 = 250;
			$value3 = 100;
			$value5 = 0;
			$value = $_POST["name"];
		  if ($value > $value1)
		$value6 = $value / $value1;
		$value7 = $value6 * $value1;
		$uus = $value - $value7;

				  if ($uus > $value2)
		$value10 = $uus / $value2;
		$value11 = $value10 * $value2;
		$uus2 = $value - $value11;

				  if ($uus2 > $value3)
		$value13 = $uus2 / $value3;
		$value14 = $value13 * $value3;
		$uus3 = $value - $value14;
		echo  "       $value6";
		echo  "       $value10";
		echo  "       $value13";


		  
		  

	
?>
</body>
</html>

My FRIEND DID THIS CODE IT DOESNT MAKE ANY SENSE RIGHT?

Link to post
Share on other sites

So yes this is possible:

<?php

$v1 = 10;
$v2 = 5;

echo $result = ($v1 / $v2); 
// output: 2

var_dump($result);
// output: int(2)

The question is more, should you write this?

I would argue for no. I think it's more readable to first only create the value $result and then echo it separately. I think it's more readable and in the end this should be your goal. The computer will always understand messy code, but humans tend to have more problem with that. Think of it like this, you should alway write code for humans first, not for computers. If you stumble across your code in a year, which would you find easier to understand (or anyone else)?

 

I would go with that. Even if it's one line longer ;)

<?php

$var1 = 10;
$var2 = 5;

$result = ( $var1 / $var2 );

echo $result;

 


Business Management Student @ University St. Gallen (Switzerland)

HomeServer: i7 4930k - GTX 780 - ASUS Rampage IV Gene - 32Gb Ram

Laptop: MacBook Pro Retina 15" 2017

Operating Systems (Virtualised using VMware): Windows Pro 10, Cent OS 7

Occupation: Building and Maintaining WebApps (Vue.js | Laravel) for SME's

Homepage: nitrosoft.ch

Link to post
Share on other sites
Posted · Original PosterOP
44 minutes ago, leodaniel said:

So yes this is possible:


<?php

$v1 = 10;
$v2 = 5;

echo $result = ($v1 / $v2); 
// output: 2

var_dump($result);
// output: int(2)

The question is more, should you write this?

I would argue for no. I think it's more readable to first only create the value $result and then echo it separately. I think it's more readable and in the end this should be your goal. The computer will always understand messy code, but humans tend to have more problem with that. Think of it like this, you should alway write code for humans first, not for computers. If you stumble across your code in a year, which would you find easier to understand (or anyone else)?

 

I would go with that. Even if it's one line longer ;)


<?php

$var1 = 10;
$var2 = 5;

$result = ( $var1 / $var2 );

echo $result;

 

my head is about to explode i have no idea at all what i should do now please help xD

Link to post
Share on other sites
4 hours ago, bomberblyat said:

my head is about to explode i have no idea at all what i should do now please help xD

Always whats more human (you and me :P) readable.

Name your variables appropriately (having var1-var15 is bad, its hard to understand what they each represent), always step by step so that it's easy to understand.

Just try to make it simple. Imagine you would have to look at your script again in 10 years... how long would you take to understand it (goal is to shorten this time). I think it's important to always code with that in mind. 

 

In the 2. code example it's really hard to understand what the code does, what the variables are. It takes quit some time to understand what it does.

 


Business Management Student @ University St. Gallen (Switzerland)

HomeServer: i7 4930k - GTX 780 - ASUS Rampage IV Gene - 32Gb Ram

Laptop: MacBook Pro Retina 15" 2017

Operating Systems (Virtualised using VMware): Windows Pro 10, Cent OS 7

Occupation: Building and Maintaining WebApps (Vue.js | Laravel) for SME's

Homepage: nitrosoft.ch

Link to post
Share on other sites
Posted · Original PosterOP · Best Answer
15 hours ago, leodaniel said:

Always whats more human (you and me :P) readable.

Name your variables appropriately (having var1-var15 is bad, its hard to understand what they each represent), always step by step so that it's easy to understand.

Just try to make it simple. Imagine you would have to look at your script again in 10 years... how long would you take to understand it (goal is to shorten this time). I think it's important to always code with that in mind. 

 

In the 2. code example it's really hard to understand what the code does, what the variables are. It takes quit some time to understand what it does.

 

i fixed it the code works it was pain in the ass, but it works xD

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now


  • Recently Browsing   0 members

    No registered users viewing this page.


×