Re: removing characters

From: Date: Tue, 06 Mar 2001 09:14:34 +0000
Subject: Re: removing characters
Groups: php.general 
Request: Send a blank email to php-general+get-42728@lists.php.net to get a copy of this message
Addressed to: Rick St Jean <rstjean@internet.look.ca> php-general@lists.php.net ** Reply to note from Rick St Jean <rstjean@internet.look.ca> Tue, 06 Mar 2001 01:47:05 -0500 A good way to do what you are asking is a combination of the last two suggestions... if( count( $Area )) { # Don't do anything if there are no entries reset( $Area ); # Handle the first one, with no 'or' list( , $Value ) = each( $Area ); $String = "(Area='$Value')"; # Handle the rest with a leading 'or' while( list( , $Value ) = each( $Area )) { $String .= " or (Area='$Value')"; } } > > I have just started with php a few days ago but in the book that I am > reading it > uses a foreach loop that is specifically for arrays. > > > foreach($Area as $key=>$value) > { > your concatination string here > } > > Rick > > At 04:45 PM 3/6/01 +1030, you wrote: > >On Tue, 6 Mar 2001 15:50, rpruitt@mid-tn.com wrote: > > > A problem of inexperience... > > > > > > I am trying to store an array in mysql. I obtain the array like so-- > > > > > > $partcount = count($Area); > > > reset($Area); > > > for ($i = 0; $i < $partcount; $i++){ > > > $key = key($Area); > > > $val = $Area[$key]; > > > $string1 .= $val . "\') or (Area=\'"; > > > next($Area); > > > } > > > > > > This results, with a bit of coaxing, in an array like this one -- > > > > > > +-----------------------------------------------------+ > > > > > > | Area | > > > > > > +-----------------------------------------------------+ > > > > > > | (Area='1') or (Area='2') or (Area='3') or > > > (Area='') | > > > > > > +-----------------------------------------------------+ > > > > > > Everything is falling into place, *except* these last thirteen > > > characters -- > > > > > > or (Area='') > > > > > > And that's what I'd like to eradicate. > > > > > > Tips, suggestions, especially outright code greatly appreciate. > > > > > > Thanks, > > > Robert > > > p.s.-- I have ordered the Friedl book on Regular Expressions. Hoping it > > > will enlighten me for the future > > > >My suggestion would be to not create the empty reference in the firast > >place :-) > > > >Before starting your loop (but after checking there is something to work > >with) use the first element of the arra to create the (Area='1') then you > >can loop through the rest of the array, starting with $i = 1 and create > > > > or (Area='$val') Rick Widmer Internet Marketing Specialists http://www.developersdesk.com

« previous php.general (#42728) next »