Jump to content

Daniel0

Staff Alumni
  • Posts

    11,885
  • Joined

  • Last visited

Everything posted by Daniel0

  1. Isn't that pretty much a paraphrase of this post?
  2. Hmm... in that case it should be an array. Try var_dump'ing it within the if just to make sure.
  3. Well, have you checked that $settings['quotes'] actually is an array?
  4. Why exactly is it you don't just pass variables by argument?
  5. If you know for sure that you are going to have to use Python in the future, but don't otherwise have plans with the other languages, then I think the choice is a no-brainer (unless your AI course simultaneously teaches Python).
  6. I don't know how your script looks, but global will only import things from the global namespace, not from the local namespace where the function was called. So something like this will not work: <?php function foo() { global $bar; echo $bar; } function bar() { $bar = 'foo'; foo(); } bar();
  7. Have you setup an SMTP server/MTA on your server?
  8. It just means you discard the first element in the array you are using list on.
  9. Which is precisely why it's bad practice. You have no real control over what writes to it when, and it's a pain to debug. I suppose you can always step through the code execution manually until you figure out what resets it.
  10. I've never played any type of MMORPG, but I'm planning to at least check out SWTOR when it's released some time next year. That's only because KOTOR I and KOTOR II (both were single player RPGs) were awesome though.
  11. It works for me. You're not calling the function in the code you posted though.
  12. That's what happens when you pollute the global namespace, and it's in particular why using global variables is bad practice. Great, now I have a case study to show people when I say this
  13. Okay, so this algorithm is much better: <?php function verifyAnagram(array $words, array $chars) { $numChars = count($chars); sort($chars); for ($i = 0, $num = count($words); $i < $num; ++$i) { if (strlen($words[$i]) === $numChars) { $c = str_split($words[$i]); sort($c); if ($c !== $chars) { unset($words[$i]); } } else { unset($words[$i]); } } sort($words); // to restore array keys return $words; } var_dump(verifyAnagram(array('car', 'truck', 'house', 'red', 'color'), array('c', 'k', 'r', 'u', 't'))); It'll return all words that can be generated using the characters.
  14. You can generate all the permutations like this: <?php function generatePermutations(array $chars) { $numChars = count($chars); if ($numChars == 1) { return $chars; } $permutations = array(); for ($i = 0; $i < $numChars; ++$i) { $orig = $chars; $first = $chars[$i]; array_splice($chars, $i, 1); // why the hell can't it just return my new array?! foreach (generatePermutations($chars) as $str) { $permutations[] = $first . $str; } $chars = $orig; } return $permutations; } var_dump(generatePermutations(array('c', 'k', 'r', 'u', 't'))); Then you can check if the word is part of the permutations. You could also modify the algorithm to stop when the permutation has been found. Note that this algorithm is Θ(n!) (we also say that it's running in factorial time), i.e. it quickly becomes slow if you have a lot of characters. For just 10 characters there will be 3628800 different permutations.
  15. Right, these things are irrelevant. Try checking if sessions work for other things than phpmyadmin. In that way we'll know if it's a problem with your PHP setup, or if it's a problem specifically with phpmyadmin.
  16. Does sessions work for other pages?
  17. There is nothing "special" about about Python. One of the important things is knowing when to use what tool. A lot of shell scripting is made in e.g. Python, and I think Gentoo's portage system is written using Python for instance.
  18. So, does it still fail or does it work now?
  19. Using mod_rewrite, you can do this: RewriteCond %{HTTPS} off RewriteRule .* https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
  20. It's a regular expression matching HTML anchor tags that will extract the HREF and TITLE attributes as well as the anchor text.
  21. Hmm... well, do you understand what it means to return a value from a function? The ternary statement will return something based on the truth value of $row[4], and the function will then return whatever the ternary statement returns.
  22. Hmm... try making sure that the session save path is readable by the webserver. Sessions are by default stored on the file system, so if PHP cannot write to that directory, sessions won't work.
  23. Well, the slideshow is made in Flash, so I couldn't possibly tell you. A typical way of centering a block element is to give it a width and then set the left and right margin to auto.
  24. Because echo doesn't return any value. You'd just want to do this: return ($row[4]) ? sprintf($html, $row[3], htmlentities( $row[1] ) ) : "hello";
×
×
  • 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.