Jump to content

silkfire

Members
  • Posts

    569
  • Joined

  • Last visited

Everything posted by silkfire

  1. Wow you're playful even in your posts =) Ye I love explode + array_pop or _shift one of the best functions in PHP =P
  2. Scriptwise, you can shorten the code by knowing that you're only interested in the portion after the last hyphen (-). $s1 = 'http://domain.com/xxx-c-39.html'; $s2 = 'http://domain.com/xxx-c-38_107.html'; preg_match('#^(\d+)[^\d]*(\d+)*#', array_pop(explode('-', $s1)), $id); echo $id[1] . (isset($id[2]) ? ', ' . $id[2]) . '<br>'; preg_match('#^(\d+)[^\d]*(\d+)*#', array_pop(explode('-', $s2)), $id); echo $id[1] . (isset($id[2]) ? ', ' . $id[2]) . '<br>';
  3. They are, but in a different format. Just modify the preg script given by kicken.
  4. Okay try this code: $cost_firstlevel = 3; // base $max_level = 1; $money = $money_left = 40; $cost = 0; if ($money > $cost_firstlevel) { while ($cost <= $money) { $cost += pow($cost_firstlevel, $max_level); $money -= $cost; $max_level++; } $money_left = $money_left - ((1 - pow($cost_firstlevel, $max_level)) / (1 - $cost_firstlevel) - 1); $max_level--; } elseif ($money == $cost_firstlevel) { $cost = $cost_firstlevel; $money_left = 0; } else $max_level--; echo "$money_left is how much money is left <br />"; // return is 1 echo "$max_level most level you can afford <br />"; // return is 3 echo "$cost cost is for the amount you can most buy <br />"; //return is 39
  5. Pardon me, I meant log() in my earlier post. By the way I think your logic is flawed and you're mixing things up. To calculate the product of exponents with the same base, we use the base raised to the power of the sums of its exponents: 31 * 32 * 33 * 34 = 3(1+2+3+4) = 310 = 59,049 To calculate the sums (as you want) you need to use this formula: (1 - b^N) / (1 - b) - n, where b = 3 (base), n = 1 (starting level), N = 4 (ending level). Expanding: (1 - 3^4) / (1 - 3) - 1 = 39 Try using this formula in your loop then calculate the rest.
  6. Why are you not using log10?
  7. eval() is handy when you want to calculate a string, i.e '(43 - 27) * 5 + 3 / 0.023' instead of having a hoarde of switch / case statements.
  8. What thorpe is trying to say is you should create a separate table for all pending ids and then have a column there cross reference to the clan_id in your clans table.
  9. What is your criteria for sorting? It doesn't make sense.
  10. What part is it you don't understand? The first row is a GROUP BY, like a summary of the five following rows, which share the same group_id. First comes a summary row, then 5 rows, and it repeats until all rows matching are retrieved.
  11. 10 to the power of 1 is 10 my friend. If you've had advanced math in high school you'd probably heard of logarithms. In this case you need common logarithm (base 10, decimal base) as opposed to natural (base e) or binary logarithm (base 2). Logarithms are used to revert exponentiation, i.e. 10x = 100. To find out x, we use log(100) = x, and log(100) = 2. The common logarithm function in PHP is log10() and natural is just log(), where you also can specify a base, default though is e. Then use floor() to get the maximum level a person can afford. Example: If you got 150 bucks, you're between 100 (102) and 1000 (103) and log(150) is 2.17609126 which when floored becomes 2. Thus you can maximum afford level 2.
  12. Hi all, does anyone know how to perform this, or if it's even possible? I need every 6th row to be a GROUP BY of the following 5 rows, they all share a common group_id so that's what the GROUP BY is performed on. 1. GROUP BY group_id 2. item #1 3. item #2 4. item #3 5. item #4 6. item #5 7. GROUP BY group_id 8. item #6 ... and so on
  13. What types of data can the $_SESSION cookie store? Objects? Resources? And how are these stored in text form?
  14. Sure there is. Use array_combine(keys, values) to create the new array. array_combine($array_with_values, $values);
  15. The Latvian alphabet uses either UTF-8 or ISO-8859-4 as the charset. Please check the collation of your MySQL fields.
  16. You might need AJAX to show a random name in a box by letting PHP read the text file line by line into an array and then spitting out a random name.
  17. PFMa, you say it's better to read in at 200k chars at a time, but how do you deal with the situation that you're not getting the full last row? Do you somehow glue it together to the next row you read, or? The lines are max 80 chars but they could be less unless padding is used to reach 80 chars/line? What does 2MB refer to?
  18. Try NL_nl.iso-8859-1 or NL_nl.utf8. If that doesn't work, do you know if your server is Unix? If so you can check which locales are installed.
  19. You're accessing the JSON object in the wrong way. Change it to: $lat = $output->Placemark[0]->Point->coordinates[1]; $long = $output->Placemark[0]->Point->coordinates[0];
  20. Invert your logic by removing the exclamation mark. ! means NOT.
  21. if ($ItemNum=="All"){ $ItemNum=$_GET['item']; if ($ItemNum=="All"){ unset($TestArray); Why do you have the same validation check here?? unset($TestArray); unset($TestArray['NumItems']); Why do you first delete the whole variable then one of its elements? Doesn't make sense. $TestArray['NumItems']=$TestArray['NumItems']-1; can be rewritten to: $TestArray['NumItems']-- if($TestArray['NumItems']<1) I assume it can't be negative? So it can only be zero. Then write: if(!$TestArray['NumItems'])
  22. Make a JavaScript solution or use a form and POST the data in the textfield.
  23. Please print your original JSON string?
  24. Maybe he means steganography, it's the art of hiding a hidden image or message within an image.
  25. Maybe you need array_merge? array_combine creates a new array from keys and values.
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.