Jump to content

silkfire

Members
  • Posts

    569
  • Joined

  • Last visited

Profile Information

  • Gender
    Not Telling
  • Location
    Stockholm, Sweden

silkfire's Achievements

Member

Member (2/5)

4

Reputation

  1. What does this give you: var_dump(curl_getinfo($ch), curl_error($ch));
  2. How do I get a static variable dynamically? I'm trying this but getting the dreaded PAAMAYIM error: foreach($this->entity::$dialog_data as $property) { Should result in Company::$dialog_data because $this->entity contains the string 'Company'.
  3. Where did you get this code from? There are Excel libraries out there, why are you making your own binary functions??
  4. I tried to login with your credentials but it says that account has been blocked. Maybe already been busted?
  5. Decodes perfectly with PHP, are you sure you did it the right way?
  6. Nowadays I only visit this forum to read Jessica's brilliant replies to lazy coders =D
  7. As per KevinM1's statement, try to avoid both the global keyword and the array $GLOBALS. Sending a variable to a function or having it as part of a construct in a class is a much more reliable solution.
  8. Replace the line: $files[] = $values['files']; with $files = array_merge($files, $values['files']);
  9. Jessica's replies to lazy help seekers - priceless
  10. He wants a script that can retrieve a list (array) with all the members of a clan in Combat Arms.
  11. I just tried my code with an example date '08/01/2012' and it worked perfectly, Jessica
  12. Comparing dates is a rather simple task in PHP. In your case I would suggest something like this: $date1 = strtotime($date1); $date2 = strtotime($date2) if ($date2 > $date1) { // CODE }
  13. It's a good practice to let functions return something instead of echoing it out, because otherwise you lose the control of knowing where in the code execution the string will be echoed out.
  14. Yeah if you even bothered to look at the solution. Here's some code for you: function array_sum_parts($n,$t,$all=false) { $count_n = count($n); // how much fields are in that array? $count = pow(2,$count_n); // we need to do 2^fields calculations to test all possibilities # now i want to look at every number from 1 to $count, where the number is representing # the array and add up all array-elements which are at positions where my actual number # has a 1-bit # EXAMPLE: # $i = 1 in binary mode 1 = 01 i'll use ony the first array-element # $i = 10 in binary mode 10 = 1010 ill use the secont and the fourth array-element # and so on... the number of 1-bits is the amount of numbers used in that try for($i=1;$i<=$count;$i++){ // start calculating all possibilities $total=0; // sum of this try $anzahl=0; // counter for 1-bits in this try $k = $i; // store $i to another variable which can be changed during the loop for($j=0;$j<$count_n;$j++){ // loop trough array-elemnts $total+=($k%2)*$n[$j]; // add up if the corresponding bit of $i is 1 $anzahl+=($k%2); // add up the number of 1-bits $k=$k>>1; //bit-shift to the left for looking at the next bit in the next loop } if ($total==$t) { $loesung[$i] = $anzahl; // if sum of this try is the sum we are looking for, save this to an array (whith the number of 1-bits for sorting) if (!$all) { break; // if we're not looking for all solutions, make a break because the first one was found } } } asort($loesung); // sort all solutions by the amount of numbers used // formating the solutions to getting back the original array-keys (which shoud be the return-value) foreach($loesung as $val=>$anzahl) { $bit = strrev(decbin($val)); $total = 0; $ret_this = array(); for($j=0; $j < strlen($bit); $j++) { if ($bit[$j] == '1') { $ret_this[] = $j; } } $ret[]=$ret_this; } return $ret; } $x = array(1, 4, 17, -9); $y = 5; var_dump(array_pop(array_sum_parts($x, $y))); Result: array (size=2) 0 => int 0 1 => int 1
×
×
  • 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.