Re: [PHP] while-question
bruce wrote: > interesting points regarding college and programming.. > > my degrees bsee/msee covered alot more than pure programing.. as a double > ee/cs, the ability to articulate an issue/problem, and bring to mind a cogent > thought process was valuable. the ability to understand how different > algorithms worked, and how code actually played with the lower intracacies of > the processor where quite valuable. > > and no.. i'm no longer the engineer i was a time ago.. > > so.. interesting... > They must have been case-insensitive languages, unlike English. :-) -Shawn -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] while-question
interesting points regarding college and programming.. my degrees bsee/msee covered alot more than pure programing.. as a double ee/cs, the ability to articulate an issue/problem, and bring to mind a cogent thought process was valuable. the ability to understand how different algorithms worked, and how code actually played with the lower intracacies of the processor where quite valuable. and no.. i'm no longer the engineer i was a time ago.. so.. interesting... -Original Message- From: Wolf [mailto:[EMAIL PROTECTED] Sent: Monday, November 17, 2008 11:55 AM To: tedd Cc: php-general@lists.php.net Subject: RE: [PHP] while-question > Dabbling? > > I think that making a living from it isn't dabbling, so I may not be > qualified to speak for the dabblers. > > But for me, I was writing code before there were such courses. Later, > when I went to college I was taught adventures in keypunching and > received several "next to worthless" degrees. > > I say "next to worthless" only because what they taught really wasn't > applicable to real world programming. As for management, clients, and > hr types, the degrees mattered, but not for much more than that. > > In any event, I doubt if any college courses are keeping up with > current web technology -- there has always been a lag between what's > practiced and what's taught. What I've seen of college web sites, > seems to support that claim. > > If I was taught in college all I needed to know, then what am I doing > with these dozens of web books scattered about my office? I probably > read a new book every other week. I don't "dabble" in it either, unless you consider making my living from being a dabbler, in which case I'll continue to dabble and see the pay for it. My alma-mater tried to stay current to some degree, but when they let someone who wrote the C++ book try to teach it, well they gave that person more rope then they needed. Tedd, glad you got hooked on Phonics. One of these days I hope from graduating from just looking at the pictures, but right now the pictures are oh so enticing!. ;) Wolf -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] while question
On Tue, 2008-11-18 at 10:52 +, Nathan Rixham wrote: > Ashley Sheridan wrote: > > On Mon, 2008-11-17 at 18:01 -0500, Craige Leeder wrote: > >> Ashley Sheridan wrote: > >>> On Mon, 2008-11-17 at 17:47 -0500, Craige Leeder wrote: > >>> > Only thing to note with the foreach is that you are actually working on > a copy of the array, so if you intend to modify it, pass it by reference. > > - Craige > > >>> Can you do that? I assume it would look like this: > >>> > >>> foreach(&$array as $a) {} > >>> > >> Close. It actually looks like this: > >> > >> foreach ($array as $key => &$value) {} > >> > >> This makes sense because for each iteration of the loop, PHP places a > >> copy of the key in $key, and a copy of the value in $value. Therefor, > >> you are specifying with this code that you want it to place a reference > >> of the value into $value. > >> > >> - Craige > >> > >> > >> > > Ah, that could be very useful to know, thanks! > > > > > > Ash > > www.ashleysheridan.co.uk > > > > foreach ($array as $key => $value) > > $value = a copy so won't change the original array > $array[$key] = the original > > thus: > > foreach ($array as $key => $value) { > $array[$key] = do_something_with($value); > } > This is how I've always done it 'til now, but I think passing by reference is a bit neater in its approach, and can be easier to read when $value is itself an array or complex object. Ash www.ashleysheridan.co.uk -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] while-question
On Tue, 2008-11-18 at 14:33 +, Nathan Rixham wrote: > Craige Leeder wrote: > > Jochem Maas wrote: > >> klieder ... kliederen > >> > >> the E sound is short. > >> > >> > > Interesting to know. Thanks :D > > > > - Craige > > don't believe him, "jochem" is really called Bob Davis, a slightly > balding middle aged ASP developer from hull Ahhh... Hull... I have memories of thee. 15 years ago between 1am and 3am that was the place to head after the Ottawa bars closed and you wanted to squeeze in another 2 hours of binging. Cheers, Rob. -- http://www.interjinn.com Application and Templating Framework for PHP -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] while-question
On Tue, Nov 18, 2008 at 9:33 AM, Nathan Rixham <[EMAIL PROTECTED]> wrote: > Craige Leeder wrote: > >> Jochem Maas wrote: >> >>> klieder ... kliederen >>> >>> the E sound is short. >>> >>> >>> >> Interesting to know. Thanks :D >> >> - Craige >> > > don't believe him, "jochem" is really called Bob Davis, a slightly balding > middle aged ASP developer from hull sent to infiltrate the PHP community and > misguide the weak with tales of short sounding letters. > > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > > Is this where we starting singing 'Pass the dutchie on the left hand side'? -- Bastien Cat, the other other white meat
Re: [PHP] while-question
Craige Leeder wrote: Jochem Maas wrote: klieder ... kliederen the E sound is short. Interesting to know. Thanks :D - Craige don't believe him, "jochem" is really called Bob Davis, a slightly balding middle aged ASP developer from hull sent to infiltrate the PHP community and misguide the weak with tales of short sounding letters. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] while-question
Jochem Maas wrote: klieder ... kliederen the E sound is short. Interesting to know. Thanks :D - Craige -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] while-question
Craige Leeder schreef: > Jochem Maas wrote: >> just for laughs .. given the 'dabble' thread "Cleeder" is phonetically >> very very close to a dutch word meaning 'messing around' .. rather in >> the way >> a 2yo might mess around with a bowl of yogurt. >> > Haha, now that does make me laugh. Out of curiosity, what is the actual > word for it? klieder ... kliederen the E sound is short. > -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] while-question
Jochem Maas wrote: just for laughs .. given the 'dabble' thread "Cleeder" is phonetically very very close to a dutch word meaning 'messing around' .. rather in the way a 2yo might mess around with a bowl of yogurt. Haha, now that does make me laugh. Out of curiosity, what is the actual word for it? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] while-question
tedd wrote: At 7:02 PM -0500 11/17/08, Craige Leeder wrote: I'm not illiterate; promise :p - Craige Yeah, his parents were married before he was born. Cheers, tedd omg tedd, I was just reading this thread over, thought exactly that witty response, clicked you're reply and there it is; masterful! -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] while question
Ashley Sheridan wrote: On Mon, 2008-11-17 at 18:01 -0500, Craige Leeder wrote: Ashley Sheridan wrote: On Mon, 2008-11-17 at 17:47 -0500, Craige Leeder wrote: Only thing to note with the foreach is that you are actually working on a copy of the array, so if you intend to modify it, pass it by reference. - Craige Can you do that? I assume it would look like this: foreach(&$array as $a) {} Close. It actually looks like this: foreach ($array as $key => &$value) {} This makes sense because for each iteration of the loop, PHP places a copy of the key in $key, and a copy of the value in $value. Therefor, you are specifying with this code that you want it to place a reference of the value into $value. - Craige Ah, that could be very useful to know, thanks! Ash www.ashleysheridan.co.uk foreach ($array as $key => $value) $value = a copy so won't change the original array $array[$key] = the original thus: foreach ($array as $key => $value) { $array[$key] = do_something_with($value); } -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] while-question
Craige Leeder schreef: > Jochem Maas wrote: >> must . resist >> >> "I take you didn't score to hig on the spelling test? and collage, >> is that the the cut-n-paste school of IT?" >> >> dang it, failed. ;-) >> > > > Haha! 'high' was just my 'h' key not pressing, and college is just one > of those words I have trouble with. I demand credit for the utter brilliance of the cut-n-paste crack ;-) > > I'm not illiterate; promise :p :-) > > - Craige just for laughs .. given the 'dabble' thread "Cleeder" is phonetically very very close to a dutch word meaning 'messing around' .. rather in the way a 2yo might mess around with a bowl of yogurt. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] while-question
tedd schreef: > At 12:52 AM +0100 11/18/08, Jochem Maas wrote: >> Craige Leeder schreef: >> > I'm 100% self taught for now. I'm just out of higschool, and hopefully >>> going off to collage next year. >> >> must . resist >> >> "I take you didn't score to hig on the spelling test? and collage, >> is that the the cut-n-paste school of IT?" >> >> dang it, failed. ;-) > > Hang in there Jochem -- he's probably smarter than we were when we were > his age. pity the poor soul ;-) being clever only gets you deeper into 'dabble'. :-P > Cheers, > > tedd -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] while question
Jay Blanchard wrote: > [snip] > ...foreach... > [/snip] > > You could also use a for loop if you wanted to count; > > for($i = 0; $i < count($array); $i++){ >echo $i . "\n"; > } > > > This is not good because you are calling count every loop iteration. Thank you, Micah Gersten onShore Networks Internal Developer http://www.onshore.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] while-question
At 7:02 PM -0500 11/17/08, Craige Leeder wrote: I'm not illiterate; promise :p - Craige Yeah, his parents were married before he was born. Cheers, tedd -- --- http://sperling.com http://ancientstones.com http://earthstones.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] while-question
At 12:52 AM +0100 11/18/08, Jochem Maas wrote: Craige Leeder schreef: > I'm 100% self taught for now. I'm just out of higschool, and hopefully going off to collage next year. must . resist "I take you didn't score to hig on the spelling test? and collage, is that the the cut-n-paste school of IT?" dang it, failed. ;-) Hang in there Jochem -- he's probably smarter than we were when we were his age. Cheers, tedd -- --- http://sperling.com http://ancientstones.com http://earthstones.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] while question
Craige Leeder schreef: > Ashley Sheridan wrote: >> On Mon, 2008-11-17 at 17:47 -0500, Craige Leeder wrote: >> >>> Only thing to note with the foreach is that you are actually working >>> on a copy of the array, so if you intend to modify it, pass it by >>> reference. >>> >>> - Craige >>> >> Can you do that? I assume it would look like this: >> >> foreach(&$array as $a) {} >> > > Close. It actually looks like this: > > foreach ($array as $key => &$value) {} > > This makes sense because for each iteration of the loop, PHP places a > copy of the key in $key, and a copy of the value in $value. Therefor, > you are specifying with this code that you want it to place a reference > of the value into $value. indeed but beware, using a variable named $value after such a foreach loop in the same scope will lead to all sorts of things you don't expect. > > - Craige > > > -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] while-question
Jochem Maas wrote: must . resist "I take you didn't score to hig on the spelling test? and collage, is that the the cut-n-paste school of IT?" dang it, failed. ;-) Haha! 'high' was just my 'h' key not pressing, and college is just one of those words I have trouble with. I'm not illiterate; promise :p - Craige -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] while-question
tedd schreef: > At 10:00 AM -0800 11/17/08, bruce wrote: >> curious qiestion >> >> to all on here who dabble in php... how many of you have actully gone to >> college, taken algorithm courses, microprocessor courses, >> design/architecture courses, etc.. >> >> or is the majority of the work here from people who've grabbed the >> tools and >> started programming... ? > > > Dabbling? Im neck deep in dabble every other week .. obviously it's always someone else dabble ;-) -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] while-question
Craige Leeder schreef: > bruce wrote: >> curious qiestion >> >> to all on here who dabble in php... how many of you have actully gone to >> college, taken algorithm courses, microprocessor courses, >> design/architecture courses, etc.. >> >> or is the majority of the work here from people who've grabbed the >> tools and >> started programming... ? >> > > I'm 100% self taught for now. I'm just out of higschool, and hopefully > going off to collage next year. must . resist "I take you didn't score to hig on the spelling test? and collage, is that the the cut-n-paste school of IT?" dang it, failed. ;-) > Everything I've learned at this stage is from books, tutorials, and > experience. > > - Craige > -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] while-question
bruce wrote: curious qiestion to all on here who dabble in php... how many of you have actully gone to college, taken algorithm courses, microprocessor courses, design/architecture courses, etc.. or is the majority of the work here from people who've grabbed the tools and started programming... ? I'm 100% self taught for now. I'm just out of higschool, and hopefully going off to collage next year. Everything I've learned at this stage is from books, tutorials, and experience. - Craige -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] while question
On Mon, 2008-11-17 at 18:01 -0500, Craige Leeder wrote: > Ashley Sheridan wrote: > > On Mon, 2008-11-17 at 17:47 -0500, Craige Leeder wrote: > > > >> Only thing to note with the foreach is that you are actually working on > >> a copy of the array, so if you intend to modify it, pass it by reference. > >> > >> - Craige > >> > > Can you do that? I assume it would look like this: > > > > foreach(&$array as $a) {} > > > > Close. It actually looks like this: > > foreach ($array as $key => &$value) {} > > This makes sense because for each iteration of the loop, PHP places a > copy of the key in $key, and a copy of the value in $value. Therefor, > you are specifying with this code that you want it to place a reference > of the value into $value. > > - Craige > > > Ah, that could be very useful to know, thanks! Ash www.ashleysheridan.co.uk -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] while question
Ashley Sheridan wrote: On Mon, 2008-11-17 at 17:47 -0500, Craige Leeder wrote: Only thing to note with the foreach is that you are actually working on a copy of the array, so if you intend to modify it, pass it by reference. - Craige Can you do that? I assume it would look like this: foreach(&$array as $a) {} Close. It actually looks like this: foreach ($array as $key => &$value) {} This makes sense because for each iteration of the loop, PHP places a copy of the key in $key, and a copy of the value in $value. Therefor, you are specifying with this code that you want it to place a reference of the value into $value. - Craige -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] while question
On Mon, 2008-11-17 at 17:47 -0500, Craige Leeder wrote: > Alain Roger wrote: > > Hi, > > > > i'm on PHP training and our lector is telling us that to avoid counting an > > array item amout thanks count($my_array), he tells we can do: > > while($my_array) > > { > > ... do something > > } > > but from experience this is an infinity loop... > > > > it should be always something like > > $count = count($my_array); > > while($i <= $count) > > { > > ... > > do something > > ... > > $i++; > > } > > > > has someone already use such syntax ? i mean as the first one. > > thx. > > > While you teacher technically is wrong, you probably could implement > something using the next() and current() array functions, though you're > best to just use a foreach loop. foreach was designed specifically as an > array looping construct, so it's optimized pretty well. > > Only thing to note with the foreach is that you are actually working on > a copy of the array, so if you intend to modify it, pass it by reference. > > - Craige > > > Can you do that? I assume it would look like this: foreach(&$array as $a) {} Ash www.ashleysheridan.co.uk -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] while question
Alain Roger wrote: Hi, i'm on PHP training and our lector is telling us that to avoid counting an array item amout thanks count($my_array), he tells we can do: while($my_array) { ... do something } but from experience this is an infinity loop... it should be always something like $count = count($my_array); while($i <= $count) { ... do something ... $i++; } has someone already use such syntax ? i mean as the first one. thx. While you teacher technically is wrong, you probably could implement something using the next() and current() array functions, though you're best to just use a foreach loop. foreach was designed specifically as an array looping construct, so it's optimized pretty well. Only thing to note with the foreach is that you are actually working on a copy of the array, so if you intend to modify it, pass it by reference. - Craige -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] while-question
At 2:55 PM -0500 11/17/08, Wolf wrote: Tedd, glad you got hooked on Phonics. One of these days I hope from graduating from just looking at the pictures, but right now the pictures are oh so enticing!. ;) Wolf Wolf: Lot's of exciting things -- hard to keep up on bots, automated buying, data mining, and other such things that make my head hurt. Cheers, tedd -- --- http://sperling.com http://ancientstones.com http://earthstones.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] while-question
> Dabbling? > > I think that making a living from it isn't dabbling, so I may not be > qualified to speak for the dabblers. > > But for me, I was writing code before there were such courses. Later, > when I went to college I was taught adventures in keypunching and > received several "next to worthless" degrees. > > I say "next to worthless" only because what they taught really wasn't > applicable to real world programming. As for management, clients, and > hr types, the degrees mattered, but not for much more than that. > > In any event, I doubt if any college courses are keeping up with > current web technology -- there has always been a lag between what's > practiced and what's taught. What I've seen of college web sites, > seems to support that claim. > > If I was taught in college all I needed to know, then what am I doing > with these dozens of web books scattered about my office? I probably > read a new book every other week. I don't "dabble" in it either, unless you consider making my living from being a dabbler, in which case I'll continue to dabble and see the pay for it. My alma-mater tried to stay current to some degree, but when they let someone who wrote the C++ book try to teach it, well they gave that person more rope then they needed. Tedd, glad you got hooked on Phonics. One of these days I hope from graduating from just looking at the pictures, but right now the pictures are oh so enticing!. ;) Wolf -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] while-question
At 10:00 AM -0800 11/17/08, bruce wrote: curious qiestion to all on here who dabble in php... how many of you have actully gone to college, taken algorithm courses, microprocessor courses, design/architecture courses, etc.. or is the majority of the work here from people who've grabbed the tools and started programming... ? Dabbling? I think that making a living from it isn't dabbling, so I may not be qualified to speak for the dabblers. But for me, I was writing code before there were such courses. Later, when I went to college I was taught adventures in keypunching and received several "next to worthless" degrees. I say "next to worthless" only because what they taught really wasn't applicable to real world programming. As for management, clients, and hr types, the degrees mattered, but not for much more than that. In any event, I doubt if any college courses are keeping up with current web technology -- there has always been a lag between what's practiced and what's taught. What I've seen of college web sites, seems to support that claim. If I was taught in college all I needed to know, then what am I doing with these dozens of web books scattered about my office? I probably read a new book every other week. Cheers, tedd -- --- http://sperling.com http://ancientstones.com http://earthstones.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] while-question
bruce wrote: curious qiestion to all on here who dabble in php... how many of you have actully gone to college, taken algorithm courses, microprocessor courses, design/architecture courses, etc.. or is the majority of the work here from people who've grabbed the tools and started programming... ? the bulk of it self taught and via vast amounts of reading and many years of on the job experience (needs must), some formal education in the form of a year wasted getting a diploma whenst I was young (mainly as the topics covered where out of date and unused in general business). HOWEVER, (a big one) I've recently converted, never really been an advocate of formal training until recently; I would highly recommend taking some certification courses (zend, sun, mysql etc), and some formal study on the finer details of programming / architecture. If I could do it all again I'd do both, work to get experience and challeges, read the great books and the manuals, and get certified properly at the same time. finally, using good tools makes a vast difference, for instance I use eclipse + pdt + zend eclipse debugger + svn + rse + bugzilla + mylyn + phpdoc + phpunit (adding in ant + cruise control to the mix soon for continuous integration) [snip myself] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] while-question
On Mon, 2008-11-17 at 19:07 +0100, Jochem Maas wrote: > Robert Cummings schreef: > > On Mon, 2008-11-17 at 14:54 +, Stut wrote: > >> On 17 Nov 2008, at 14:31, Nathan Rixham wrote: > >>> if you really want a challenge try this one.. > >>> > >>> task: add the numbers 5 and 17 together, using php, without using > >>> the + operator. fill it in: > >>> > >>> function add($a , $b) { > >>> //code here but no + - / * operators > >>> return $answer; > >>> } > >>> > >>> echo add(5, 17); > >> Elemental my dear Mr Rixham... > > > > What level is that elemental? > > well it's all bitwise operating ... can't get much more > elemental that a bit in CS. but I think he meant to > say elementary (assuming the Sherlocks Holmes catchphrase) > > > > >> function add($a , $b) > >> { > >>$answer = $a ^ $b; > >>while (0 != ($a & $b)) > >>{ > >> $b = ($a & $b) << 1; > >> $answer = $answer ^ $b; > >>} > >>return $answer; > >> } > > nice, I think :P > > > He only said you couldn't use the + operator... nothing was said about > > using the - operator. > > > //code here but no + - / * operators > Oh... duh! :) You know what they say, if you're going to say something, say it all in one place, not part of something in one place, and the rest later on. Not everyone reads to the end you insensitive clod ;) Cheers, Rob. -- http://www.interjinn.com Application and Templating Framework for PHP -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] while-question
On Mon, 2008-11-17 at 10:00 -0800, bruce wrote: > curious qiestion > > to all on here who dabble in php... how many of you have actully gone to > college, taken algorithm courses, microprocessor courses, > design/architecture courses, etc.. > > or is the majority of the work here from people who've grabbed the tools and > started programming... ? I think it's a mixed crowd here. I have a Bachelor of Computer Science. The various algorithms courses were some of my favourite courses in the program along with parallel and distributed computing. Cheers, Rob. -- http://www.interjinn.com Application and Templating Framework for PHP -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] while-question
Robert Cummings schreef: > On Mon, 2008-11-17 at 14:54 +, Stut wrote: >> On 17 Nov 2008, at 14:31, Nathan Rixham wrote: >>> if you really want a challenge try this one.. >>> >>> task: add the numbers 5 and 17 together, using php, without using >>> the + operator. fill it in: >>> >>> function add($a , $b) { >>> //code here but no + - / * operators >>> return $answer; >>> } >>> >>> echo add(5, 17); >> Elemental my dear Mr Rixham... > > What level is that elemental? well it's all bitwise operating ... can't get much more elemental that a bit in CS. but I think he meant to say elementary (assuming the Sherlocks Holmes catchphrase) > >> function add($a , $b) >> { >>$answer = $a ^ $b; >>while (0 != ($a & $b)) >>{ >> $b = ($a & $b) << 1; >> $answer = $answer ^ $b; >>} >>return $answer; >> } nice, I think :P > He only said you couldn't use the + operator... nothing was said about > using the - operator. //code here but no + - / * operators > > $total = -(-5 - 17); > > Cheers, > Rob. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] while-question
curious qiestion to all on here who dabble in php... how many of you have actully gone to college, taken algorithm courses, microprocessor courses, design/architecture courses, etc.. or is the majority of the work here from people who've grabbed the tools and started programming... ? -Original Message- From: Robert Cummings [mailto:[EMAIL PROTECTED] Sent: Monday, November 17, 2008 9:53 AM To: Stut Cc: Nathan Rixham; php-general@lists.php.net Subject: Re: [PHP] while-question On Mon, 2008-11-17 at 14:54 +, Stut wrote: > On 17 Nov 2008, at 14:31, Nathan Rixham wrote: > > if you really want a challenge try this one.. > > > > task: add the numbers 5 and 17 together, using php, without using > > the + operator. fill it in: > > > > function add($a , $b) { > > //code here but no + - / * operators > > return $answer; > > } > > > > echo add(5, 17); > > Elemental my dear Mr Rixham... What level is that elemental? > function add($a , $b) > { >$answer = $a ^ $b; >while (0 != ($a & $b)) >{ > $b = ($a & $b) << 1; > $answer = $answer ^ $b; >} >return $answer; > } He only said you couldn't use the + operator... nothing was said about using the - operator. $total = -(-5 - 17); Cheers, Rob. -- http://www.interjinn.com Application and Templating Framework for PHP -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] while-question
On Mon, 2008-11-17 at 14:54 +, Stut wrote: > On 17 Nov 2008, at 14:31, Nathan Rixham wrote: > > if you really want a challenge try this one.. > > > > task: add the numbers 5 and 17 together, using php, without using > > the + operator. fill it in: > > > > function add($a , $b) { > > //code here but no + - / * operators > > return $answer; > > } > > > > echo add(5, 17); > > Elemental my dear Mr Rixham... What level is that elemental? > function add($a , $b) > { >$answer = $a ^ $b; >while (0 != ($a & $b)) >{ > $b = ($a & $b) << 1; > $answer = $answer ^ $b; >} >return $answer; > } He only said you couldn't use the + operator... nothing was said about using the - operator. $total = -(-5 - 17); Cheers, Rob. -- http://www.interjinn.com Application and Templating Framework for PHP -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] while-question
Stut wrote: On 17 Nov 2008, at 14:31, Nathan Rixham wrote: if you really want a challenge try this one.. task: add the numbers 5 and 17 together, using php, without using the + operator. fill it in: function add($a , $b) { //code here but no + - / * operators return $answer; } echo add(5, 17); Elemental my dear Mr Rixham... function add($a , $b) { $answer = $a ^ $b; while (0 != ($a & $b)) { $b = ($a & $b) << 1; $answer = $answer ^ $b; } return $answer; } -Stut what an answer; very nice and indeed full marks mr stut! now then.. echo add(5,17) . ' ' . (5 + 17) . PHP_EOL; echo add(-5,17) . ' ' . (-5 + 17) . PHP_EOL; echo add(5,-17) . ' ' . (5 + -17) . PHP_EOL; echo add(-5,-17) . ' ' . (-5 + -17) . PHP_EOL; (can you tell I've been down this route before?) -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] while-question
On Mon, Nov 17, 2008 at 9:47 AM, Jochem Maas <[EMAIL PROTECTED]> wrote: > Nathan Rixham schreef: >> Jochem Maas wrote: >>> $a = range(1,10); >>> for ($i = 0, $c = count($a); $i < $c; print($a[$i]."\n"), $i++); >> >> think the point of this is to count the items in an array without count >> mate :p no point in the above you could just: >> $c = count($a); > > I thought the point was to avoid count() on every iteration. > not using count() but instead looping the complete array is stupid, > if the OP's teacher thinks count() is bad then that teacher suck's, > count() is efficient as it can be ... it does'nt actually do a > count when it's called merely looks up the length property of the > array (unless I'm grossly mistaken) > >> >> foreach! >> $a = range(1,10); >> $c = 0; >> foreach($a as $b) { >> $c++; >> } >> echo $c. PHP_EOL; >> >> if you really want a challenge try this one.. >> >> task: add the numbers 5 and 17 together, using php, without using the + >> operator. fill it in: >> >> function add($a , $b) { >> //code here but no + - / * operators > > I'll assume no post/pre-increment operators either. > >> return $answer; >> } >> >> echo add(5, 17); > > function add($a, $b) { >$a = array_merge(array_fill(0, $a, 1), array_fill(0, $b, 1)); >return count($a); > } > > not very efficient :-) .. probably one of a 1000 ways to fudge it :-) > And another... :) function add($a, $b) { return array_sum(func_get_args()); } Andrew -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] while-question
On 17 Nov 2008, at 14:31, Nathan Rixham wrote: if you really want a challenge try this one.. task: add the numbers 5 and 17 together, using php, without using the + operator. fill it in: function add($a , $b) { //code here but no + - / * operators return $answer; } echo add(5, 17); Elemental my dear Mr Rixham... function add($a , $b) { $answer = $a ^ $b; while (0 != ($a & $b)) { $b = ($a & $b) << 1; $answer = $answer ^ $b; } return $answer; } -Stut -- http://stut.net/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] while-question
Nathan Rixham schreef: > Jochem Maas wrote: >> $a = range(1,10); >> for ($i = 0, $c = count($a); $i < $c; print($a[$i]."\n"), $i++); > > think the point of this is to count the items in an array without count > mate :p no point in the above you could just: > $c = count($a); I thought the point was to avoid count() on every iteration. not using count() but instead looping the complete array is stupid, if the OP's teacher thinks count() is bad then that teacher suck's, count() is efficient as it can be ... it does'nt actually do a count when it's called merely looks up the length property of the array (unless I'm grossly mistaken) > > foreach! > $a = range(1,10); > $c = 0; > foreach($a as $b) { > $c++; > } > echo $c. PHP_EOL; > > if you really want a challenge try this one.. > > task: add the numbers 5 and 17 together, using php, without using the + > operator. fill it in: > > function add($a , $b) { > //code here but no + - / * operators I'll assume no post/pre-increment operators either. > return $answer; > } > > echo add(5, 17); function add($a, $b) { $a = array_merge(array_fill(0, $a, 1), array_fill(0, $b, 1)); return count($a); } not very efficient :-) .. probably one of a 1000 ways to fudge it :-) > -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] while-question
Jochem Maas wrote: $a = range(1,10); for ($i = 0, $c = count($a); $i < $c; print($a[$i]."\n"), $i++); think the point of this is to count the items in an array without count mate :p no point in the above you could just: $c = count($a); foreach! $a = range(1,10); $c = 0; foreach($a as $b) { $c++; } echo $c. PHP_EOL; if you really want a challenge try this one.. task: add the numbers 5 and 17 together, using php, without using the + operator. fill it in: function add($a , $b) { //code here but no + - / * operators return $answer; } echo add(5, 17); -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] while-question
Timo Erbach schreef: > ...but for best performance you should do: > > > $counter = count($array); > for($i = 0; $i < $counter; $i++){ > echo $i . "\n"; > } just for fun: $a = range(1,10); for ($i = 0, $c = count($a); $i < $c; print($a[$i]."\n"), $i++); ... gives an idea of the power and flexibility of a for loop constructor, i.e. you can pretty much write a complete program using just a for construct without even defining a loop body. > > So the expression count() in the for()-loop is only > parsed once and not every loop. > > Regards > Timo > [snip] > ...foreach... > [/snip] > > You could also use a for loop if you wanted to count; > > for($i = 0; $i < count($array); $i++){ > echo $i . "\n"; > } > > -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] while-question
...but for best performance you should do: $counter = count($array); for($i = 0; $i < $counter; $i++){ echo $i . "\n"; } So the expression count() in the for()-loop is only parsed once and not every loop. Regards Timo [snip] ...foreach... [/snip] You could also use a for loop if you wanted to count; for($i = 0; $i < count($array); $i++){ echo $i . "\n"; } -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] while question
[snip] ...foreach... [/snip] You could also use a for loop if you wanted to count; for($i = 0; $i < count($array); $i++){ echo $i . "\n"; } -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] while question
Hi, i'm on PHP training and our lector is telling us that to avoid counting an array item amout thanks count($my_array), he tells we can do: while($my_array) { ... do something } but from experience this is an infinity loop... it should be always something like $count = count($my_array); while($i <= $count) { ... do something ... $i++; } has someone already use such syntax ? i mean as the first one. thx. Probably the easiest way for doing this is using foreach: $a = array(1,2,3,4,5); foreach ($a as $i) { print $i.""; } This outputs: 1 2 3 4 5 This for e.g. gives an infinite loop: $a = array(1,2,3,4,5); while ($a) { print $i.""; $i++; } So you are right because $a will always evaluate as true since it not empty. For these kinds of questions you should read the manual first and then ask here. http://gr2.php.net/manual/en/control-structures.while.php -- Thodoris -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] while question
On 17 Nov 2008, at 13:01, Alain Roger wrote: i'm on PHP training and our lector is telling us that to avoid counting an array item amout thanks count($my_array), he tells we can do: while($my_array) { ... do something } but from experience this is an infinity loop... it should be always something like $count = count($my_array); while($i <= $count) { ... do something ... $i++; } has someone already use such syntax ? i mean as the first one. The while would work if you removed elements of $my_array inside the loop, but you would still need to be sure that it would eventually be empty. I would guess that your lecturers point is that you shouldn't call count on every iteration as it's a waste of time. He may also be confusing while for foreach in which case I'd leave because you're unlikely to learn anything from him. -Stut -- http://stut.net/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] while question
Hi, i'm on PHP training and our lector is telling us that to avoid counting an array item amout thanks count($my_array), he tells we can do: while($my_array) { ... do something } but from experience this is an infinity loop... it should be always something like $count = count($my_array); while($i <= $count) { ... do something ... $i++; } has someone already use such syntax ? i mean as the first one. thx. -- Alain Windows XP SP3 PostgreSQL 8.2.4 / MS SQL server 2005 Apache 2.2.4 PHP 5.2.4 C# 2005-2008