Daniel0
Staff Alumni-
Posts
11,885 -
Joined
-
Last visited
Everything posted by Daniel0
-
Can't you just concatenate them together?
-
I think I tried to install it once and found that it was incompatible for some reason.
-
[SOLVED] I want shoutbox in freaks and you?
Daniel0 replied to xcoderx's topic in PHPFreaks.com Website Feedback
A shoutbox is not going to happen. If you want live chat we've got an IRC channel like SA said. I'm also moving this to the correct board. -
We need a smiley of someone getting whacked with the ban hammer.
-
[SOLVED] Storing lots of constants outside the class?
Daniel0 replied to ifubad's topic in PHP Coding Help
Storing a lot of constants usually wouldn't be a good idea regardless. -
Oh race does exist, but what the Human Genome Project shows is that there are no human races in the biological sense. An anthropologist might still say that human races exist because they have different metrics for determining race.
-
Well, the thing is that he is trying to implement a simple math DSL and running it through eval() doesn't accomplish this. Even if he did he would still have to parse and verify that it's a correct format, in which case he might as well just finish the interpreter.
-
If you're looking for speedy insertion in the beginning you should look at another data structure than arrays such as a linked list. Putting something in the beginning of an array is by nature an expensive operation because you have to move all the other elements upwards. See this quick benchmark for instance: $iterations = 10000; $start = microtime(true); $array = array(); for ($i = 0; $i < $iterations; ++$i) { array_unshift($array, $i); } echo 'Total time (array): ' . (microtime(true) - $start) . PHP_EOL; unset($array); $start = microtime(true); $memory = memory_get_usage(true); $list = new SplDoublyLinkedList(); for ($i = 0; $i < $iterations; ++$i) { $list->unshift($i); } echo 'Total time (linked list): ' . (microtime(true) - $start) . PHP_EOL;
-
[SOLVED] Question about arrays - Advanced
Daniel0 replied to Ninjakreborn's topic in PHP Coding Help
Something like this should do: uasort($bigarray, create_function('$a,$b', 'return count($a) > count($b);')); usort, uasort -
In Denmark there is this really obnoxious person called Jonni Hansen who has an equally obnoxious political party called Danmarks Nationalsocialistiske Bevægelse (National Socialist Movement of Denmark). Essentially a neo-Nazi party. To them, that someone's skin color is different is sufficient enough reason to "dislike" them.
-
That's because a while loop functions differently than a foreach loop. A while loop continues as long as the statement is true (or rather "while it's true it continues"). mysql_fetch_array() has an internal cursor that it moves forward each time you call it. As long as you've not exceeded the amount of rows returned it will return a value that can evaluate to true. That is why you can get all the rows using while, and why it will not work with foreach (because foreach takes a preexisting array and iterates over all the elements). If you wanted to output all the fields in a row you could do like this: while ($row = mysql_fetch_array($widgets)) { echo '<tr>'; foreach ($row as $field) { echo '<td>' . $field . '</td>'; } echo '</tr>'; }
-
Right, composition denotes ownership of the contained object whereas aggregation does not. Like a university has a composition of departments and the departments have an aggregate of professors and students. Strictly speaking, snippet 1 is aggregation and snippet 2 is composition, but often the distinction doesn't matter.
-
I suppose what the article fails to consider is that two fields can use the same term in different ways. The way anthropology uses the term "race" needn't necessarily be the way biology uses it. Case in point, compare the way mainstream media uses the term "hacker" with the way a person like Eric S. Raymond would use it. In reality, it doesn't matter what we call it. "Racism" as FUD regarding people who "look differently" will not go away just because we pick another term for it and say "biologically you cannot really call it 'races'". This FUD is a manifestation of the fear of that which is different. A black person still looks different than a white person. The article says: That's just switching one term with another. If you don't like black people (as a white person) you just don't like black people. Saying "I don't like them because they have a different skin color" is just as irrational as saying "I don't like them because they're a different race".
-
Biologically a race is a subset of a species. Organisms in the same species, but in distinct races have certain differences in their biological traits but their chromosomes are still sufficiently similar that reproduction across these races is indeed possible. Really it's a kind of inbreeding over a long period of time within that particular group of species. Typically you say that organisms of same species is capable of having offspring. Of course you can go bang a donkey, but it's biologically impossible to result in any offspring and that makes donkeys and humans different species. If too races would get completely isolated for a long time (or just for whatever reason not cross-breed at all) this would eventually result in the development of two distinct species and the two groups would no longer be able to cross-breed.
-
Well, neither of them is really "storing" the object, but they are storing a reference to the object in memory. Garbage collection should kick in when the last reference to an object is destroyed, so you're right, in snippet 1 the Person object will persist even when the Account object is destroyed. To be honest, there is really no better option. For a regular web page, the automatic garbage collection is typically good enough that you don't have to manually unset variables.
-
Like this? <?php $files = array(); foreach (new DirectoryIterator('/some/path') as $file) { if ($file->isDir()) continue; $files[] = array( 'name' => $file->getFilename(), 'changed' => $file->getMTime(), ); } $count = count($files); usort($files, create_function('$a,$b', 'return $a["changed"] < $b["changed"];')); If you use PHP 5.3 you can replace the last line with usort($files, function ($a, $b) { return $a['changed'] < $b['changed']; });
-
So like this? $content = preg_replace('~(<[^>]+>)' . preg_quote($check, '~') . '(</[^>]+>)~', '$1<b>$2</b>$3', $content);
-
Well, that's the users own fault for leaving the page. It's then up to the browser to decide the best course of action should the user use their browsing history to go back again. Two browsers may handle it differently, and as far as I know there is no standard determining what to do in that case.
-
Well, they're functionally the same. I suppose you would call something an association if some object A is related to some other object B, which is the case in both your scenarios.
-
You said: That would indicate a formatted string, but your function seems to take a UNIX timestamp as argument. That could possibly explain the unexpected behavior.
-
[SOLVED] count the list of results of a while loop in php?
Daniel0 replied to newb's topic in PHP Coding Help
Please do not abuse the edit feature to dramatically alter content after another post has been submitted. This kind of behavior is the reason why editing is time limited in the first place. -
All characters are always escaped using the backslash character, including the backslash, so that would be \\ You should use preg_match instead of ereg though. ereg() is slower than preg_match() and it's officially deprecated in PHP 5.3.
-
You could look into patterns such as Active Record, Data Access Object and/or Table Data Gateway. There is really no definite solution.
-
[SOLVED] count the list of results of a while loop in php?
Daniel0 replied to newb's topic in PHP Coding Help
Can't you just have an int and increment it each time? That way you should end up with the total number of elements in the end. -
Just generate the form again and output the values directly into the form elements instead of relying on the browser history.