Skip to main content
replaced http://stackoverflow.com/ with https://stackoverflow.com/
Source Link

Not exactly a PHP expert but your $weapons array:

$weapons = array(
  0 => "Scattergun",
  1 => "Pistol",
  2 => "Rocket%20Launcher",
  3 => "Direct%20Hit",
  .
  .
  .
  29 => "Knife",
);

You do not need an associative array for this. In fact, I would discourage this. Although there may be no good reason to do this, imagine you want to add a weapon in the middle, then you have to change a lot of numbers.

Similarly, I do not know how PHP internally represents associative arrays, but they may be slower to access than a standard array. C++ implementations often use Red-Black TreesRed-Black Trees to implement something similar to associative arrays and other languages may use other data structures.

Just use the standard array:

$weapons = array(
  "Scattergun",
  "Pistol",
  "Rocket%20Launcher",
  "Direct%20Hit",
   .
   .
   .
  "Knife",
);

Use a foreach loop:

for($wep_counter = 0; $wep_counter < count($weapons); $wep_counter++) {

  $url = "http://steamcommunity.com/market/listings/440/Strange%20". $weapons[$wep_counter];       # get listing for that weapon type

becomes:

foreach ($weapons as $weapon) { # I don't believe you are mutating a value so I don't believe the "&" prefix is necessary.

  $url = "http://steamcommunity.com/market/listings/440/Strange%20". $weapon; 

There could be other issues but I'm not too much of a PHP expert, but these issues pertain to a lot of languages. I would definitely be sure to keep these in mind when using other languages as well.

Not exactly a PHP expert but your $weapons array:

$weapons = array(
  0 => "Scattergun",
  1 => "Pistol",
  2 => "Rocket%20Launcher",
  3 => "Direct%20Hit",
  .
  .
  .
  29 => "Knife",
);

You do not need an associative array for this. In fact, I would discourage this. Although there may be no good reason to do this, imagine you want to add a weapon in the middle, then you have to change a lot of numbers.

Similarly, I do not know how PHP internally represents associative arrays, but they may be slower to access than a standard array. C++ implementations often use Red-Black Trees to implement something similar to associative arrays and other languages may use other data structures.

Just use the standard array:

$weapons = array(
  "Scattergun",
  "Pistol",
  "Rocket%20Launcher",
  "Direct%20Hit",
   .
   .
   .
  "Knife",
);

Use a foreach loop:

for($wep_counter = 0; $wep_counter < count($weapons); $wep_counter++) {

  $url = "http://steamcommunity.com/market/listings/440/Strange%20". $weapons[$wep_counter];       # get listing for that weapon type

becomes:

foreach ($weapons as $weapon) { # I don't believe you are mutating a value so I don't believe the "&" prefix is necessary.

  $url = "http://steamcommunity.com/market/listings/440/Strange%20". $weapon; 

There could be other issues but I'm not too much of a PHP expert, but these issues pertain to a lot of languages. I would definitely be sure to keep these in mind when using other languages as well.

Not exactly a PHP expert but your $weapons array:

$weapons = array(
  0 => "Scattergun",
  1 => "Pistol",
  2 => "Rocket%20Launcher",
  3 => "Direct%20Hit",
  .
  .
  .
  29 => "Knife",
);

You do not need an associative array for this. In fact, I would discourage this. Although there may be no good reason to do this, imagine you want to add a weapon in the middle, then you have to change a lot of numbers.

Similarly, I do not know how PHP internally represents associative arrays, but they may be slower to access than a standard array. C++ implementations often use Red-Black Trees to implement something similar to associative arrays and other languages may use other data structures.

Just use the standard array:

$weapons = array(
  "Scattergun",
  "Pistol",
  "Rocket%20Launcher",
  "Direct%20Hit",
   .
   .
   .
  "Knife",
);

Use a foreach loop:

for($wep_counter = 0; $wep_counter < count($weapons); $wep_counter++) {

  $url = "http://steamcommunity.com/market/listings/440/Strange%20". $weapons[$wep_counter];       # get listing for that weapon type

becomes:

foreach ($weapons as $weapon) { # I don't believe you are mutating a value so I don't believe the "&" prefix is necessary.

  $url = "http://steamcommunity.com/market/listings/440/Strange%20". $weapon; 

There could be other issues but I'm not too much of a PHP expert, but these issues pertain to a lot of languages. I would definitely be sure to keep these in mind when using other languages as well.

added 345 characters in body
Source Link
Dair
  • 6.2k
  • 1
  • 21
  • 45

Not exactly a PHP expert but your $weapons array:

$weapons = array(
  0 => "Scattergun",
  1 => "Pistol",
  2 => "Rocket%20Launcher",
  3 => "Direct%20Hit",
  .
  .
  .
  29 => "Knife",
);

You do not need an associative array for this. In fact, I would discourage this. Although there may be no good reason to do this, imagine you want to add a weapon in the middle, then you have to change a lot of numbers.

Similarly, I do not know how PHP internally represents associative arrays, but they may be slower to access than a standard array. C++ implementations often use Red-Black Trees to implement something similar to associative arrays and other languages may use other data structures.

Just use the standard array:

$weapons = array(
  "Scattergun",
  "Pistol",
  "Rocket%20Launcher",
  "Direct%20Hit",
   .
   .
   .
  "Knife",
);

Use a foreach loop:

for($wep_counter = 0; $wep_counter < count($weapons); $wep_counter++) {

  $url = "http://steamcommunity.com/market/listings/440/Strange%20". $weapons[$wep_counter];       # get listing for that weapon type

becomes:

foreach ($weapons as $weapon) { # I don't believe you are mutating a value so I don't believe the "&" prefix is necessary.

  $url = "http://steamcommunity.com/market/listings/440/Strange%20". $weapon; 

There could be other issues but I'm not too much of a PHP expert, but these issues pertain to a lot of languages. I would definitely be sure to keep these in mind when using other languages as well.

Not exactly a PHP expert but your $weapons array:

$weapons = array(
  0 => "Scattergun",
  1 => "Pistol",
  2 => "Rocket%20Launcher",
  3 => "Direct%20Hit",
  .
  .
  .
  29 => "Knife",
);

You do not need an associative array for this. In fact, I would discourage this. Although there may be no good reason to do this, imagine you want to add a weapon in the middle, then you have to change a lot of numbers. Just use the standard array:

$weapons = array(
  "Scattergun",
  "Pistol",
  "Rocket%20Launcher",
  "Direct%20Hit",
   .
   .
   .
  "Knife",
);

Use a foreach loop:

for($wep_counter = 0; $wep_counter < count($weapons); $wep_counter++) {

  $url = "http://steamcommunity.com/market/listings/440/Strange%20". $weapons[$wep_counter];       # get listing for that weapon type

becomes:

foreach ($weapons as $weapon) { # I don't believe you are mutating a value so I don't believe the "&" prefix is necessary.

  $url = "http://steamcommunity.com/market/listings/440/Strange%20". $weapon; 

There could be other issues but I'm not too much of a PHP expert, but these issues pertain to a lot of languages. I would definitely be sure to keep these in mind when using other languages as well.

Not exactly a PHP expert but your $weapons array:

$weapons = array(
  0 => "Scattergun",
  1 => "Pistol",
  2 => "Rocket%20Launcher",
  3 => "Direct%20Hit",
  .
  .
  .
  29 => "Knife",
);

You do not need an associative array for this. In fact, I would discourage this. Although there may be no good reason to do this, imagine you want to add a weapon in the middle, then you have to change a lot of numbers.

Similarly, I do not know how PHP internally represents associative arrays, but they may be slower to access than a standard array. C++ implementations often use Red-Black Trees to implement something similar to associative arrays and other languages may use other data structures.

Just use the standard array:

$weapons = array(
  "Scattergun",
  "Pistol",
  "Rocket%20Launcher",
  "Direct%20Hit",
   .
   .
   .
  "Knife",
);

Use a foreach loop:

for($wep_counter = 0; $wep_counter < count($weapons); $wep_counter++) {

  $url = "http://steamcommunity.com/market/listings/440/Strange%20". $weapons[$wep_counter];       # get listing for that weapon type

becomes:

foreach ($weapons as $weapon) { # I don't believe you are mutating a value so I don't believe the "&" prefix is necessary.

  $url = "http://steamcommunity.com/market/listings/440/Strange%20". $weapon; 

There could be other issues but I'm not too much of a PHP expert, but these issues pertain to a lot of languages. I would definitely be sure to keep these in mind when using other languages as well.

Source Link
Dair
  • 6.2k
  • 1
  • 21
  • 45

Not exactly a PHP expert but your $weapons array:

$weapons = array(
  0 => "Scattergun",
  1 => "Pistol",
  2 => "Rocket%20Launcher",
  3 => "Direct%20Hit",
  .
  .
  .
  29 => "Knife",
);

You do not need an associative array for this. In fact, I would discourage this. Although there may be no good reason to do this, imagine you want to add a weapon in the middle, then you have to change a lot of numbers. Just use the standard array:

$weapons = array(
  "Scattergun",
  "Pistol",
  "Rocket%20Launcher",
  "Direct%20Hit",
   .
   .
   .
  "Knife",
);

Use a foreach loop:

for($wep_counter = 0; $wep_counter < count($weapons); $wep_counter++) {

  $url = "http://steamcommunity.com/market/listings/440/Strange%20". $weapons[$wep_counter];       # get listing for that weapon type

becomes:

foreach ($weapons as $weapon) { # I don't believe you are mutating a value so I don't believe the "&" prefix is necessary.

  $url = "http://steamcommunity.com/market/listings/440/Strange%20". $weapon; 

There could be other issues but I'm not too much of a PHP expert, but these issues pertain to a lot of languages. I would definitely be sure to keep these in mind when using other languages as well.