Re: Invalid Argument why?

From: Date: Thu, 16 Jul 2009 20:09:38 +0000
Subject: Re: Invalid Argument why?
References: 1 2  Groups: php.general 
Request: Send a blank email to php-general+get-295496@lists.php.net to get a copy of this message
foreach iterates over an array or a object (see Traversable ). If you pass anything different he complains <?php if( !is_scalar( $collection ) ) foreach( $collection as $element ) print_r( $element ); On Thu, Jul 16, 2009 at 4:53 PM, Kyle Smith <kyle.smith@inforonics.com>wrote: > Miller, Terion wrote: > >> Why is this an invalid argument? >> >> foreach(($row['inType']) as $inType){ >> >> echo $inType,'<br>';} >> >> I am trying to output results from a data base that may have multiple >> results for the same name.... >> >> So trying to use an array and foreach that is the right track ...right? >> >> >> >> > Looks like you meant to do something like this: > > // Always better to be plural when you have an array. > $rows = whatever_your_rows_come_from(); > > foreach($rows as $row) > { > $inType = $row['inType']; > echo $inType . '<br />'; > } > > > HTH, > Kyle > -- Martin Scotta

« previous php.general (#295496) next »