[PHP] Re: Foreach and mydql_query problem

2013-07-22 Thread Tim Streater
On 22 Jul 2013 at 12:56, Karl-Arne Gjersøyen karlar...@gmail.com wrote: Yes, i know that only one a singe row is updated and that is the problem. What can I do to update several rows at the same time? Which several rows? The row that will be updated is that (or those) that match your WHERE

[PHP] Re: Foreach and mydql_query problem

2013-07-22 Thread Karl-Arne Gjersøyen
2013/7/22 Tim Streater t...@clothears.org.uk On 22 Jul 2013 at 12:56, Karl-Arne Gjersøyen karlar...@gmail.com wrote: Yes, i know that only one a singe row is updated and that is the problem. What can I do to update several rows at the same time? Which several rows? The row that will be

Re: [PHP] Mystery foreach error

2013-03-13 Thread Jim Giner
On 3/12/2013 9:04 PM, Angela Barone wrote: On Mar 12, 2013, at 5:16 PM, David Robley wrote: Presumably there is a fixed list of State - those are US states? - so why not provide a drop down list of the possible choices? There is, but the problem must have been that if someone

Re: [PHP] Mystery foreach error

2013-03-13 Thread Matijn Woudt
On Wed, Mar 13, 2013 at 5:07 PM, Jim Giner jim.gi...@albanyhandball.comwrote: On 3/12/2013 9:04 PM, Angela Barone wrote: On Mar 12, 2013, at 5:16 PM, David Robley wrote: Presumably there is a fixed list of State - those are US states? - so why not provide a drop down list of the possible

Re: [PHP] Mystery foreach error

2013-03-13 Thread Angela Barone
On Mar 13, 2013, at 9:07 AM, Jim Giner wrote: Why not just check if the $state exists as a key of the array $states before doing this? Jim, Are you thinking about the in_array function? Angela

Re: [PHP] Mystery foreach error

2013-03-13 Thread Matijn Woudt
On Thu, Mar 14, 2013 at 12:18 AM, Angela Barone ang...@italian-getaways.com wrote: On Mar 13, 2013, at 9:07 AM, Jim Giner wrote: Why not just check if the $state exists as a key of the array $states before doing this? Jim, Are you thinking about the in_array function? Angela

Re: [PHP] Mystery foreach error

2013-03-13 Thread Angela Barone
On Mar 13, 2013, at 4:24 PM, Matijn Woudt wrote: That wouldn't work, in_array checks the values, and your states are in the keys. Use: if(isset($states[$state])) Hi Matijn, Before I received your email, I ran across if(array_key_exists) and it seems to work. How does that differ

Re: [PHP] Mystery foreach error

2013-03-13 Thread David Harkness
On Wed, Mar 13, 2013 at 4:44 PM, Angela Barone ang...@italian-getaways.comwrote: I ran across if(array_key_exists) and it seems to work. How does that differ from if(isset($states[$state]))? Hi Angela, isset() will return false for an array key 'foo' mapped to a null value whereas

Re: [PHP] Mystery foreach error

2013-03-13 Thread Sebastian Krebs
2013/3/14 David Harkness davi...@highgearmedia.com On Wed, Mar 13, 2013 at 4:44 PM, Angela Barone ang...@italian-getaways.comwrote: I ran across if(array_key_exists) and it seems to work. How does that differ from if(isset($states[$state]))? Hi Angela, isset() will return false for

Re: [PHP] Mystery foreach error

2013-03-13 Thread David Harkness
On Wed, Mar 13, 2013 at 5:10 PM, Sebastian Krebs krebs@gmail.comwrote: Because 'null' is the representation of nothing array_key_exists() and isset() can be treated as semantically equivalent. As I said, these functions return different results for null values. It won't matter for Angela

Re: [PHP] Mystery foreach error

2013-03-13 Thread Sebastian Krebs
2013/3/14 David Harkness davi...@highgearmedia.com On Wed, Mar 13, 2013 at 5:10 PM, Sebastian Krebs krebs@gmail.comwrote: Because 'null' is the representation of nothing array_key_exists() and isset() can be treated as semantically equivalent. As I said, these functions return

Re: [PHP] Mystery foreach error

2013-03-13 Thread Angela Barone
On Mar 13, 2013, at 5:02 PM, David Harkness wrote: isset() will return false for an array key 'foo' mapped to a null value whereas array_key_exists() will return true. The latter asks Is this key in the array? whereas isset() adds and is its value not null? While isset() is

[PHP] Mystery foreach error

2013-03-12 Thread Angela Barone
I've been getting the following error for awhile now, but I can't figure out why it's happening: Invalid argument supplied for foreach() in ... sample.php on line 377 Here's that portion of code: include(states_zipcodes.php); // Check if Zip Code matches from states_zipcodes

Re: [PHP] Mystery foreach error

2013-03-12 Thread Marco Behnke
Am 12.03.13 20:45, schrieb Angela Barone: I've been getting the following error for awhile now, but I can't figure out why it's happening: Invalid argument supplied for foreach() in ... sample.php on line 377 Here's that portion of code: include(states_zipcodes.php); //

Re: [PHP] Mystery foreach error

2013-03-12 Thread Angela Barone
On Mar 12, 2013, at 2:26 PM, Marco Behnke wrote: what is in $states? Looks like $states[$state] is not an array. Here's a sample: ?php $states = array( 'AL' = array( '350','351','352','353', ), 'AK' = array( '995','996','997','998','999', ), 'AZ' = array(

Re: [PHP] Mystery foreach error

2013-03-12 Thread Jim Giner
$states = array( 'AL' = array( '350','351','352','353', ), 'AK' = array( '995','996','997','998','999', ), 'AZ' = array( '850','851','852','853','854', ), ... 'WI' = array( '530','531','532', ), 'WY' = array( '820','821','822','823','824', ), ); ? Seeing

Re: [PHP] Mystery foreach error

2013-03-12 Thread Angela Barone
I think I figured it out. ?php $states = array( 'AL' = array( '350','351','352','353', ), 'AK' = array( '995','996','997','998','999', ), 'AZ' = array( '850','851','852','853','854', ), 'WI' = array( '530','531','532', ), 'WY' = array( '820','821','822','823','824',

Re: [PHP] Mystery foreach error

2013-03-12 Thread David Robley
Angela Barone wrote: I think I figured it out. ?php $states = array( 'AL' = array( '350','351','352','353', ), 'AK' = array( '995','996','997','998','999', ), 'AZ' = array( '850','851','852','853','854', ), 'WI' = array( '530','531','532', ), 'WY' = array(

Re: [PHP] Mystery foreach error

2013-03-12 Thread Angela Barone
On Mar 12, 2013, at 5:16 PM, David Robley wrote: Presumably there is a fixed list of State - those are US states? - so why not provide a drop down list of the possible choices? There is, but the problem must have been that if someone didn't select a State, $state was blank. I've

[PHP] Re: foreach

2012-04-05 Thread Jim Giner
I don't know about others, but I can't make sense of this - way too much presented with no idea of what I am looking at - code or output. One thing: $_Request is not the same var as $_REQUEST. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit:

[PHP] Re: foreach

2012-04-05 Thread Al
On 4/5/2012 4:15 PM, Ethan Rosenberg wrote: Dear Lists - I know I am missing something fundamental - but I have no idea where to start to look. Here are code snippets: I have truncated the allowed_fields to make it easier to debug. $allowed_fields = array( 'Site' ='POST[Site]', 'MedRec' =

Re: [PHP] Strange foreach reference issue

2012-01-09 Thread David Harkness
On Sat, Jan 7, 2012 at 5:01 PM, Tim Behrendsen t...@behrendsen.com wrote: The first loop is leaving a reference to the final element. But then the second foreach is doing a straight assignment to the $row variable, but $row is a reference to the final element. So the foreach is assigning its

Re: [PHP] Strange foreach reference issue

2012-01-09 Thread Tim Behrendsen
On 1/9/2012 10:35 AM, David Harkness wrote: On Sat, Jan 7, 2012 at 5:01 PM, Tim Behrendsen t...@behrendsen.com mailto:t...@behrendsen.com wrote: The first loop is leaving a reference to the final element. But then the second foreach is doing a straight assignment to the $row

Re: [PHP] Strange foreach reference issue

2012-01-08 Thread Adi Mutu
...@gmail.com Sent: Sunday, January 8, 2012 3:01 AM Subject: Re: [PHP] Strange foreach reference issue On 1/7/2012 4:44 PM, Stephen wrote: On 12-01-07 07:30 PM, Tim Behrendsen wrote: When you use an ampersand on the variable, that creates a reference to the array elements, allowing you to potentially

[PHP] Strange foreach reference issue

2012-01-07 Thread Tim Behrendsen
Hello, This sure looks like a bug, but maybe there's some subtlety going on that I don't understand, so I would appreciate some insight. After much debugging, I tracked down a bug in my code to this test program. My PHP version is 5.3.3, running under Fedora Linux. ?php $row_list =

Re: [PHP] Strange foreach reference issue

2012-01-07 Thread Stephen
I cut and pasted your code and got the same result. I flipped the two foreach blocks and got the expected results. I deleted the first block and copied the second, then updated the string. I got this. I can't explain. ?php $row_list = array( array( 'Title' = 'Title

Re: [PHP] Strange foreach reference issue

2012-01-07 Thread Matijn Woudt
On Sun, Jan 8, 2012 at 12:29 AM, Tim Behrendsen t...@behrendsen.com wrote: Hello, This sure looks like a bug, but maybe there's some subtlety going on that I don't understand, so I would appreciate some insight. After much debugging, I tracked down a bug in my code to this test program. My

Re: [PHP] Strange foreach reference issue

2012-01-07 Thread Tim Behrendsen
On 1/7/2012 4:18 PM, Matijn Woudt wrote: On Sun, Jan 8, 2012 at 12:29 AM, Tim Behrendsent...@behrendsen.com wrote: Hello, This sure looks like a bug, but maybe there's some subtlety going on that I don't understand, so I would appreciate some insight. After much debugging, I tracked down a

Re: [PHP] Strange foreach reference issue

2012-01-07 Thread Stephen
On 12-01-07 07:30 PM, Tim Behrendsen wrote: When you use an ampersand on the variable, that creates a reference to the array elements, allowing you to potentially change the array elements themselves (which I'm not doing here). http://www.php.net/manual/en/control-structures.foreach.php I

Re: [PHP] Strange foreach reference issue

2012-01-07 Thread Tim Behrendsen
On 1/7/2012 4:44 PM, Stephen wrote: On 12-01-07 07:30 PM, Tim Behrendsen wrote: When you use an ampersand on the variable, that creates a reference to the array elements, allowing you to potentially change the array elements themselves (which I'm not doing here).

RE: [PHP] Possible foreach bug; seeking advice to isolate the problem

2010-10-22 Thread Ford, Mike
-Original Message- From: Jonathan Sachs [mailto:081...@jhsachs.com] Sent: 20 October 2010 04:48 To: php-general@lists.php.net Subject: [PHP] Possible foreach bug; seeking advice to isolate the problem I've got a script which originally contained the following piece of code

Re: [PHP] Possible foreach bug; seeking advice to isolate the problem

2010-10-20 Thread richard gray
On 20/10/2010 05:47, Jonathan Sachs wrote: I've got a script which originally contained the following piece of code: foreach ( $objs as $obj ) { do_some_stuff($obj); } When I tested it, I found that on every iteration of the loop the last element of $objs was assigned the value of the

[PHP] Possible foreach bug; seeking advice to isolate the problem

2010-10-19 Thread Jonathan Sachs
I've got a script which originally contained the following piece of code: foreach ( $objs as $obj ) { do_some_stuff($obj); } When I tested it, I found that on every iteration of the loop the last element of $objs was assigned the value of the current element. I was able to step through the

Re: [PHP] Question - foreach.

2010-06-11 Thread tedd
At 3:46 PM -0400 6/10/10, Paul M Foster wrote: On Thu, Jun 10, 2010 at 11:16:08AM -0400, tedd wrote: I spend much of my time thinking Did I do that before? grin I know the feeling. I will say this, though. I have yet to figure out, from your URLs, how your site(s) is/are organized. Maybe a

Re: [PHP] Question - foreach.

2010-06-10 Thread tedd
At 7:19 AM +0530 6/10/10, Shreyas wrote: PHP'ers, I am reading a PHP book which explains foreach and at the end says : *'When foreach starts walking through an array, it moves the pointer to the beginning of the array. You don't need to reset an array before walking through it with foreach.'* *

Re: [PHP] Question - foreach.

2010-06-10 Thread Paul M Foster
On Thu, Jun 10, 2010 at 07:03:28AM -0400, tedd wrote: At 7:19 AM +0530 6/10/10, Shreyas wrote: PHP'ers, I am reading a PHP book which explains foreach and at the end says : *'When foreach starts walking through an array, it moves the pointer to the beginning of the array. You don't need to

Re: [PHP] Question - foreach.

2010-06-10 Thread Shreyas
All, I tried and tested it but wanted a solid confirmation on it. I felt foreach usage is better than manual way of next(), prev() et al. Thanks for the comments. I consider the thread answered and solved unless someone has anything more to add. Regards, Shreyas On Thu, Jun 10, 2010 at 7:02

Re: [PHP] Question - foreach.

2010-06-10 Thread tedd
At 9:32 AM -0400 6/10/10, Paul M Foster wrote: On Thu, Jun 10, 2010 at 07:03:28AM -0400, tedd wrote: This is one of those questions that you can test very easily, just initialize an array and try it. +1 This is Tedd's modus operandi. His website(s) are full of exactly this type of thing.

Re: [PHP] Question - foreach.

2010-06-10 Thread Paul M Foster
On Thu, Jun 10, 2010 at 11:16:08AM -0400, tedd wrote: At 9:32 AM -0400 6/10/10, Paul M Foster wrote: On Thu, Jun 10, 2010 at 07:03:28AM -0400, tedd wrote: This is one of those questions that you can test very easily, just initialize an array and try it. +1 This is Tedd's modus

RE: [PHP] Question - foreach.

2010-06-10 Thread Bob McConnell
From: Paul M Foster On Thu, Jun 10, 2010 at 11:16:08AM -0400, tedd wrote: At 9:32 AM -0400 6/10/10, Paul M Foster wrote: On Thu, Jun 10, 2010 at 07:03:28AM -0400, tedd wrote: Paul: Now, if I could get the old memory to lock in and remember it, it would be great! I spend much of my

Re: [PHP] Question - foreach.

2010-06-10 Thread David McGlone
On Thursday 10 June 2010 11:16:08 tedd wrote: At 9:32 AM -0400 6/10/10, Paul M Foster wrote: On Thu, Jun 10, 2010 at 07:03:28AM -0400, tedd wrote: This is one of those questions that you can test very easily, just initialize an array and try it. +1 This is Tedd's modus operandi.

[PHP] Question - foreach.

2010-06-09 Thread Shreyas
PHP'ers, I am reading a PHP book which explains foreach and at the end says : *'When foreach starts walking through an array, it moves the pointer to the beginning of the array. You don’t need to reset an array before walking through it with foreach.'* * * *Does this mean - * *1) Before I

Re: [PHP] Question - foreach.

2010-06-09 Thread Adam Richardson
On Wed, Jun 9, 2010 at 9:49 PM, Shreyas shreya...@gmail.com wrote: PHP'ers, I am reading a PHP book which explains foreach and at the end says : *'When foreach starts walking through an array, it moves the pointer to the beginning of the array. You don’t need to reset an array before

Re: [PHP] Question - foreach.

2010-06-09 Thread Jim Lucas
Shreyas wrote: PHP'ers, I am reading a PHP book which explains foreach and at the end says : *'When foreach starts walking through an array, it moves the pointer to the beginning of the array. You don’t need to reset an array before walking through it with foreach.'* * * *Does this mean - * *1)

Re: [PHP] Question - foreach.

2010-06-09 Thread Daniel Brown
On Wed, Jun 9, 2010 at 21:49, Shreyas shreya...@gmail.com wrote: PHP'ers, I am reading a PHP book which explains foreach and at the end says : *'When foreach starts walking through an array, it moves the pointer to the beginning of the array. You don’t need to reset an array before walking

Re: [PHP] Embedding foreach loops

2009-08-12 Thread Ashley Sheridan
On Tue, 2009-08-11 at 16:00 -0400, Eddie Drapkin wrote: On Tue, Aug 11, 2009 at 3:56 PM, teddtedd.sperl...@gmail.com wrote: At 12:44 PM -0700 8/11/09, Ben Dunlap wrote: This is probably flame-war tinder, so I'll try to tread more delicately in the future. Next you know we'll be on the

Re: [PHP] Embedding foreach loops

2009-08-12 Thread Ashley Sheridan
On Tue, 2009-08-11 at 16:23 -0400, Rick Duval wrote: OK, first guys, I'm sorry to have to do this but I can't get off this list!!! I've followed the instructions on a couple of occasions (the ones at the bottom of every email): PHP General Mailing List (http://www.php.net/) To

Re: [PHP] Embedding foreach loops

2009-08-11 Thread hessiess
Do *NOT* get into the habit of outputting your HTML using echo or print statements, it becomes unmaintainable very quickly, use a templating language, ether with a framework(recomended) or standalone. You should learn the basics of HTML and CSS, go and read http://htmldog.com/, btw to add a

Re: [PHP] Embedding foreach loops

2009-08-11 Thread Ashley Sheridan
On Tue, 2009-08-11 at 07:13 +, hessi...@hessiess.com wrote: Do *NOT* get into the habit of outputting your HTML using echo or print statements, it becomes unmaintainable very quickly, use a templating language, ether with a framework(recomended) or standalone. You should learn the basics

Re: [PHP] Embedding foreach loops

2009-08-11 Thread sono-io
On Aug 11, 2009, at 12:13 AM, hessi...@hessiess.com wrote: Do *NOT* get into the habit of outputting your HTML using echo or print statements, it becomes unmaintainable very quickly, use a templating language, ether with a framework(recomended) or standalone. This sounds interesting.

Re: [PHP] Embedding foreach loops

2009-08-11 Thread Ben Dunlap
statements, it becomes unmaintainable very quickly, use a templating language, ether with a framework(recomended) or standalone. But he /is/ using a templating language... PHP. ;-) Ben

Re: [PHP] Embedding foreach loops

2009-08-11 Thread Robert Cummings
Ben Dunlap wrote: statements, it becomes unmaintainable very quickly, use a templating language, ether with a framework(recomended) or standalone. But he /is/ using a templating language... PHP. ;-) Keep telling yourself that... and be sure to pat your own back. Cheers, Rob. --

Re: [PHP] Embedding foreach loops

2009-08-11 Thread hessiess
= str_replace(if, ?php if, $this-str); $this-str = str_replace(eif~, ?php endif;?, $this-str); // Expand loop macro $this-str = str_replace(loop, ?php foreach, $this-str); $this-str = str_replace(eloop~, ?php endforeach;?, $this-str); // Expand display macro $this-str

Re: [PHP] Embedding foreach loops

2009-08-11 Thread Ben Dunlap
statements, it becomes unmaintainable very quickly, use a templating language, ether with a framework(recomended) or standalone. But he /is/ using a templating language... PHP. ;-) Keep telling yourself that... and be sure to pat your own back. I'm sure there are plenty of situations

Re: [PHP] Embedding foreach loops

2009-08-11 Thread tedd
At 12:44 PM -0700 8/11/09, Ben Dunlap wrote: This is probably flame-war tinder, so I'll try to tread more delicately in the future. Next you know we'll be on the ternary operator and which is better, Mac or Windows. ;-) Ben That was won long ago, it's Mac. :-) Cheers, tedd -- ---

Re: [PHP] Embedding foreach loops

2009-08-11 Thread Eddie Drapkin
On Tue, Aug 11, 2009 at 3:56 PM, teddtedd.sperl...@gmail.com wrote: At 12:44 PM -0700 8/11/09, Ben Dunlap wrote: This is probably flame-war tinder, so I'll try to tread more delicately in the future. Next you know we'll be on the ternary operator and which is better, Mac or Windows. ;-) Ben

Re: [PHP] Embedding foreach loops

2009-08-11 Thread John Butler
Allen, you off and running again? Sure am, thanks, on to the next set of issues. Seems like programming is always moving on from one error to the next :) Currently, I am having trouble with echo and php line-returns. It works on one part of the code, but not on another (instead, prints

Re: [PHP] Embedding foreach loops

2009-08-11 Thread Rick Duval
OK, first guys, I'm sorry to have to do this but I can't get off this list!!! I've followed the instructions on a couple of occasions (the ones at the bottom of every email): PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php Been There, done

Re: [PHP] Embedding foreach loops

2009-08-11 Thread Robert Cummings
Let me be the first to welcome you to the list!!! Rick Duval wrote: OK, first guys, I'm sorry to have to do this but I can't get off this list!!! I've followed the instructions on a couple of occasions (the ones at the bottom of every email): PHP General Mailing List (http://www.php.net/)

Re: [PHP] Embedded foreach loops

2009-08-10 Thread John Butler
On Aug 10, 2009, at 3:43 PM, Jim Lucas wrote: Allen McCabe wrote: I am creating an order form for tickets for a list of performances at a performing arts center. Currently, the form is on paper, and is set up as follows: -Nutcracker - Tues 10/13 - 11am - $4.00 Thanks for letting us know

Re: [PHP] Embedding foreach loops

2009-08-10 Thread Jonathan Tapicer
/23/2009';  $show_02['time'] = '11am';  $show_02['price'] = 4.00;  $show_02['soldout'] = 0; //IF THE SHOW SELLS OUT, CHANGE 0 to 1 (without quotations). [/code] And here are the foreach loops I'm trying to build the rows with: [code=order.php] ?php foreach ($shows as $key = $value

Re: [PHP] Embedding foreach loops

2009-08-10 Thread John Butler
I can't seem to get my foreach loops to work, will PHP parse embedded loops? yes. Is this something I need to have in a database to work? no, you can do it with the arrays... but it may be easier to work with over the long run if that data was in a db. Anyway right after you finish

Re: [PHP] Embedding foreach loops

2009-08-10 Thread Allen McCabe
John, I did this, and got my arrays dumped (on one line). After adding line returns, here is a snippet: [code=array dump] array(38) { [show_01]= array(5) { [title]= string(29) Van Cliburn Gold Medal Winner [date]= string(16) Tues. 10/13/2009 [time]= string(4) 11am [price]= float(4) [soldout]=

Re: [PHP] Embedding foreach loops

2009-08-10 Thread John Butler
I did this, and got my arrays dumped (on one line). After adding line returns, here is a snippet: it looks OK. Note that you can see (copy/paste) that array which you just dumped, much better, if you view the source code of the html page. OR you can use pre to make that format persist

Re: [PHP] Embedding foreach loops

2009-08-10 Thread Allen McCabe
I am using the print function to display my html. I cannot get the line return ( \n ) character to actually push the html onto the next line, it just gets displayed instead. Should I be using echo? On Mon, Aug 10, 2009 at 3:41 PM, John Butler govinda.webdnat...@gmail.comwrote: I did this,

Re: [PHP] Embedding foreach loops

2009-08-10 Thread Ben Dunlap
$shows = array();  $show_01 = array();  $show_01['title'] = 'Van Cliburn Gold Medal Winner';  $show_01['date'] = 'Tues. 10/13/2009';  $show_01['time'] = '11am';  $show_01['price'] = 4.00;  $show_01['soldout'] = 0; //IF THE SHOW SELLS OUT, CHANGE 0 to 1 (without quotations).  

RE: [PHP] Embedding foreach loops

2009-08-10 Thread Daevid Vincent
You're not using the pre and /pre tag most likely then. -Original Message- From: Allen McCabe [mailto:allenmcc...@gmail.com] Sent: Monday, August 10, 2009 4:11 PM To: John Butler Cc: phpList Subject: Re: [PHP] Embedding foreach loops I am using the print function to display my

Re: [PHP] Embedding foreach loops

2009-08-10 Thread Ben Dunlap
I am using the print function to display my html. I cannot get the line return ( \n ) character to actually push the html onto the next line, it just gets displayed instead. Should I be using echo? In the PHP code snippet you pasted above, you're using single-quotes to delimit your literal

Re: [PHP] Embedding foreach loops

2009-08-10 Thread John Butler
I am using the print function to display my html. I cannot get the line return ( \n ) character to actually push the html onto the next line, it just gets displayed instead. Should I be using echo? Allen, you off and running again? echo blah.. \n; //-- this will print the literal 'blah..

[PHP] Re: foreach and destroying variables for memory saving

2008-12-10 Thread Carlos Medina
Tim | iHostNZ schrieb: Hi All, Just to annoy the hell out of you, another thing that has been on my mind for a while: I love the foreach ($ar as $k = $v) { ... } construct and use it all the time. However, I read somewhere that foreach actually uses a copy of $ar instead of the array itself by

[PHP] Re: foreach and destroying variables for memory saving

2008-12-10 Thread Gal Gur-Arie
Tim | iHostNZ wrote: Hi All, Just to annoy the hell out of you, another thing that has been on my mind for a while: I love the foreach ($ar as $k = $v) { ... } construct and use it all the time. However, I read somewhere that foreach actually uses a copy of $ar instead of the array

[PHP] Re: foreach questions

2008-01-01 Thread jekillen
On Jan 1, 2008, at 11:59 AM, Martin Jerga wrote: Hello, the problem is in this part of code $key - $value This notation means that you are trying to access property $value on the object $key. Just replace it with $key = $value and you will get the result as expected. Martin J Thank

[PHP] Re: foreach questions

2008-01-01 Thread Martin Jerga
Hello, the problem is in this part of code $key - $value This notation means that you are trying to access property $value on the object $key. Just replace it with $key = $value and you will get the result as expected. Martin J jekillen wrote / napísal(a): Hello; I have this section of

Re: [PHP] Re: foreach questions

2008-01-01 Thread Richard Lynch
Hit send too soon. Sorry! On Tue, January 1, 2008 2:05 pm, jekillen wrote: Several questions: How long can an index be in an associative array? (the indexes I use in this array are 32 character hashes) As far as I know, it can be as big as your RAM will hold... Can it start with a number

Re: [PHP] Re: foreach questions

2008-01-01 Thread jekillen
On Jan 1, 2008, at 3:34 PM, Richard Lynch wrote: Hit send too soon. Sorry! On Tue, January 1, 2008 2:05 pm, jekillen wrote: Several questions: How long can an index be in an associative array? (the indexes I use in this array are 32 character hashes) As far as I know, it can be as big as

Re: [PHP] Rewind foreach loop

2007-11-30 Thread Robert Cummings
On Fri, 2007-11-30 at 14:46 -0500, Robert Cummings wrote: This is dangerous use of the array functions. A problem occurs when you have a value that evaluates to false (such as the first entry in the example array :). In fact the only way to ensure you traverse the array properly is to use

Re: [PHP] Rewind foreach loop

2007-11-30 Thread Robert Cummings
On Fri, 2007-11-30 at 09:51 -0800, Jim Lucas wrote: Jeffery Fernandez wrote: Hi all, Is it possible to rewind a foreach loop? eg: $numbers = array(0,1,2,3,4,5,6,7,8,9,10); foreach ($numbers as $index = $value) { if ($value == 5) {

Re: [PHP] Rewind foreach loop

2007-11-30 Thread Jim Lucas
Jeffery Fernandez wrote: Hi all, Is it possible to rewind a foreach loop? eg: $numbers = array(0,1,2,3,4,5,6,7,8,9,10); foreach ($numbers as $index = $value) { if ($value == 5) { prev($numbers); } echo Value: $value . PHP_EOL; } The above

Re: [PHP] Rewind foreach loop

2007-11-30 Thread Jochem Maas
Jeffery Fernandez wrote: Hi all, Is it possible to rewind a foreach loop? eg: $numbers = array(0,1,2,3,4,5,6,7,8,9,10); foreach ($numbers as $index = $value) { if ($value == 5) { prev($numbers); } echo Value: $value . PHP_EOL; }

[PHP] Rewind foreach loop

2007-11-29 Thread Jeffery Fernandez
Hi all, Is it possible to rewind a foreach loop? eg: $numbers = array(0,1,2,3,4,5,6,7,8,9,10); foreach ($numbers as $index = $value) { if ($value == 5) { prev($numbers); } echo Value: $value . PHP_EOL; } The above doesn't seem to work. In one of

Re: [PHP] Rewind foreach loop

2007-11-29 Thread Jeffery Fernandez
I think the best option for me is to refactorise my code a bit to cater to my situation. Thanks all for your help. Jeffery On Fri, 30 Nov 2007 02:32:11 pm Jeffery Fernandez wrote: On Fri, 30 Nov 2007 02:13:52 pm Chris wrote: Jeffery Fernandez wrote: On Fri, 30 Nov 2007 02:01:47 pm Chris

Re: [PHP] Rewind foreach loop

2007-11-29 Thread Casey
$keys = array_values($array); for ($i=0; $icount($keys); $i++) { if ($keys[$i] == 5) $i -= 2; } Untested, but should work. On Nov 29, 2007, at 7:13 PM, Chris [EMAIL PROTECTED] wrote: Jeffery Fernandez wrote: On Fri, 30 Nov 2007 02:01:47 pm Chris wrote: Jeffery Fernandez wrote:

Re: [PHP] Rewind foreach loop

2007-11-29 Thread Steve Edberg
At 2:11 PM +1100 11/30/07, Jeffery Fernandez wrote: On Fri, 30 Nov 2007 02:01:47 pm Chris [EMAIL PROTECTED] wrote: Jeffery Fernandez wrote: Hi all, Is it possible to rewind a foreach loop? eg: $numbers = array(0,1,2,3,4,5,6,7,8,9,10); foreach ($numbers as $index = $value) {

Re: [PHP] Rewind foreach loop

2007-11-29 Thread Chris
Jeffery Fernandez wrote: Hi all, Is it possible to rewind a foreach loop? eg: $numbers = array(0,1,2,3,4,5,6,7,8,9,10); foreach ($numbers as $index = $value) { if ($value == 5) { prev($numbers); } echo Value: $value . PHP_EOL; } The above

Re: [PHP] Rewind foreach loop

2007-11-29 Thread Jeffery Fernandez
On Fri, 30 Nov 2007 02:01:47 pm Chris wrote: Jeffery Fernandez wrote: Hi all, Is it possible to rewind a foreach loop? eg: $numbers = array(0,1,2,3,4,5,6,7,8,9,10); foreach ($numbers as $index = $value) { if ($value == 5) { prev($numbers);

Re: [PHP] Rewind foreach loop

2007-11-29 Thread Chris
Jeffery Fernandez wrote: On Fri, 30 Nov 2007 02:01:47 pm Chris wrote: Jeffery Fernandez wrote: Hi all, Is it possible to rewind a foreach loop? eg: $numbers = array(0,1,2,3,4,5,6,7,8,9,10); foreach ($numbers as $index = $value) { if ($value == 5) {

Re: [PHP] Rewind foreach loop

2007-11-29 Thread Jeffery Fernandez
On Fri, 30 Nov 2007 02:13:52 pm Chris wrote: Jeffery Fernandez wrote: On Fri, 30 Nov 2007 02:01:47 pm Chris wrote: Jeffery Fernandez wrote: Hi all, Is it possible to rewind a foreach loop? eg: $numbers = array(0,1,2,3,4,5,6,7,8,9,10); foreach ($numbers as $index = $value) {

Re: [PHP] for/foreach speed

2007-08-26 Thread Richard Lynch
On Mon, August 20, 2007 11:50 am, Sascha Braun, CEO @ fit-o-matic wrote: could somebody please explain me, what loop construct is faster? The for, while or foreach. If you are doing anything where the speed of for/while/foreach matters, you shouldn't have done that in PHP in the first place,

[PHP] for/foreach speed

2007-08-20 Thread Sascha Braun, CEO @ fit-o-matic
Hi people, could somebody please explain me, what loop construct is faster? The for, while or foreach. I at the moment don't know if there are more. And thanks to the person who is missusing the list here for sending trojan horses everywhere. Since I write to the PHP General list I am

Re: [PHP] for/foreach speed

2007-08-20 Thread Robert Cummings
On Mon, 2007-08-20 at 18:50 +0200, Sascha Braun, CEO @ fit-o-matic wrote: Hi people, could somebody please explain me, what loop construct is faster? The for, while or foreach. I haven't bothered testing but I'd wager $5 that the following is the fastest loop: ?php while( 1 ) { } ?

Re: [PHP] for/foreach speed

2007-08-20 Thread Sascha Braun, CEO @ fit-o-matic
Thank you very much. When we might have time for testing we can wager :)) Am Montag, den 20.08.2007, 13:21 -0400 schrieb Robert Cummings: On Mon, 2007-08-20 at 18:50 +0200, Sascha Braun, CEO @ fit-o-matic wrote: Hi people, could somebody please explain me, what loop construct is

Re: [PHP] Nested foreach statement

2006-08-03 Thread Richard Lynch
It will probably work, and you could find out for sure by just trying it. It might be better to construct a single query using things like: $company_ids = implode(', ', $_POST['reporton_company']); $query .= WHERE company_id IN ($company_ids) ; This presumes you have already validated the

[PHP] Nested foreach statement

2006-07-31 Thread Chris Grigor
Have been wondering if this is possible Basically I have 3 posted arrays, $_POST['reporton_company'] (this can be various company id's. ie 3,6,7) $_POST['report_period'] (this can be various periods but a max of 4 submitted. ie 3,4,5) $_POST['questions_groups'] (this can be various -

Re: [PHP] Nested foreach statement

2006-07-31 Thread chris smith
foreach($_POST['reporton_company'] as $cmp_ind =$arrayd_cmp_id) { foreach($_POST['report_period'] as $rep_ind =$arrayd_per_id) { foreach($_POST['questions_groups'] as $group_ind = $arrayd_group_no) { mysql_select_db($database_name, $dname); Why

[PHP] Re: foreach / unset

2005-10-29 Thread Bogdan Ribic
Richard Lynch wrote: Anyway, can you do *this* safely as a DOCUMENTED FEATURE: foreach($array as $k = $v){ if (...) unset($array[$k]); } Well, somewhere in the said manual it is written that foreach operates on a *copy* of the array, so you should be safe unsetting values in the

[PHP] Re: Foreach problem.

2005-02-09 Thread Jason Barnett
Since you didn't post how you created the array, I went ahead and (ugh!) did it myself. This works fine. ?php $elementsarr = Array ('knr', 'subject', 'title', 'kat', 'pages', 'access', 'dofile', MAX_FILE_SIZE, 'pdf', 'dolink', 'link', 'erstam', 'endless', 'from', 'until', 'openbem', 'history',

Re: [PHP] Nested foreach ?

2004-10-18 Thread Stuart Felenstein
Not working. foreach($_SESSION['skills'] as $key = $skill) { $query = INSERT INTO table (skill, sky, sku) VALUES ('$skill', {$_SESSION['skys'][$key]},{$_SESSION['slus'][$key]}); //run query } The foreach is generating an invalid argument. I'm just going to show again what I have

RE: [PHP] Nested foreach ?

2004-10-18 Thread Graham Cossey
Felenstein [mailto:[EMAIL PROTECTED] Sent: 18 October 2004 08:24 To: John Holmes; [EMAIL PROTECTED] Subject: Re: [PHP] Nested foreach ? Not working. foreach($_SESSION['skills'] as $key = $skill) { $query = INSERT INTO table (skill, sky, sku) VALUES ('$skill', {$_SESSION['skys'][$key

RE: [PHP] Nested foreach ?

2004-10-18 Thread Stuart Felenstein
Wish I had better news. Warning: Invalid argument supplied for foreach() in /home/lurkkcom/public_html/TestMultiTrans2.php on line 90 INSERT INTO LurkProfiles_Skicerts (ProfileID, SkilCerts, NumYear, Lused) VALUES () line 90: foreach($skills as $key = $skill) To confirm : I changed to this:

RE: [PHP] Nested foreach ?

2004-10-18 Thread Graham Cossey
to by several clients. HTH Graham -Original Message- From: Stuart Felenstein [mailto:[EMAIL PROTECTED] Sent: 18 October 2004 09:37 To: Graham Cossey; [EMAIL PROTECTED] Subject: RE: [PHP] Nested foreach ? Wish I had better news. Warning: Invalid argument supplied for foreach

  1   2   >