Re: Class help

Niel Archer <[email protected]>
Newsgroups gmane.comp.php.windows
Message-ID <[email protected]>
> Evening all,
> 
> I am starting to learn OOP and I am creating a class that validates an 
> array of data to save me escaping and validating:
> 
> public function validateArray($testArray)
>      {
>          $cxn->connection()
> 
>          foreach($testArray as $sub)
>          {
>              // 1
>              echo $sub . '<br/><br/>';
>          }
>      }
> 
> At // 1 i am going to escape and validate data, but then want to rebuild 
> the array to pass back.
> 
> I cannot work the rebuild of array, can you assist?

Depending on your array, if it is numerically indexed you might be
better off working directly on its elements instead of indirectly with
foreach.

public function validateArray($testArray)
{
    $count = count($testArray);
     for($i=0; $i < $count; ++$i)
     {
          // 1
          echo $testArray[i] . '<br/><br/>';
     }
    return $testArray
}

If you want to work directly on the original array (not a copy passed
into the function), then use a reference in the function signature and
drop the return statement.

public function validateArray(&$testArray)

http://www.php.net/manual/en/language.references.whatdo.php
--
Niel Archer


-- 
PHP Windows Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.