NameSilo

How to return an Array as return

SpaceshipSpaceship
SpaceshipSpaceship
SpaceshipSpaceship
Watch

desibhupi

New Member
Impact
0
Hello every body

I want to filter all the $_POST variables thru a functiion and want to return the filtered keys along with their values.

below is the sinppet that what i need actually.

PHP:
$field = $_POST;          // all the POST fields

$filtered = filter($field);

$field1 = $filtered['field1'];
$fieldn = $filtered['fieldn'];     // and so on

i want you guys to please give me hint for making the filter() function;

Regards
Bhupinder
 
0
Close
The views expressed on this page by users and staff are their own, not those of NamePros.
GoDaddyGoDaddy
PHP:
function filter($array){
     $search_for = "what you want to filter by";
     $i=1;
     $output = array();

     foreach($array as $array_value){
          if(eregi($search_for,$array_value)){
               $output['value'.$i] = $array_value;
          }
          $i++;
     }
     return $output;
}

havent tested it, but it should work.
 
0
Close
I would probably tweak that code:

Code:
     foreach($array as $key => $array_value){
          if(eregi($search_for,$array_value)){
               $output[$key] = $array_value;
          }
     }

That way the returned filtered array has the same keys as the source.
 
0
Close
TwistMyArm said:
I would probably tweak that code:

Code:
     foreach($array as $key => $array_value){
          if(eregi($search_for,$array_value)){
               $output[$key] = $array_value;
          }
     }

That way the returned filtered array has the same keys as the source.
Thanks buddies for ur instant support.
i will try the latter, but will keep in mind the ealier too. :)

Regards,
Bhupi
 
0
Close
Appraise.net

We're social

Escrow.com
Spaceship
Domain Recover
CryptoExchange.com

NamePros updates

Switch between accounts
You can now stay logged in to more than one NamePros account in the same browser. Click your avatar, then "Accounts in this browser", to...
AIVikings
Catchy
  • The sidebar remains visible by scrolling at a speed relative to the page’s height.
Back