Dynadot .com transfer sale, only $10.12 with coupon code DYNA12, available while supplies last, ends October 31, 2026.

How to return an Array as return

Namecheap AuctionsNamecheap Auctions
Namecheap AuctionsNamecheap Auctions
Spacemail by SpaceshipSpacemail by Spaceship
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
•••
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
•••
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
•••
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
•••
AIVikingsAIVikings

We're social

Escrow.com
Spaceship
Escrowly
CryptoExchange.com
Domain Recover

NamePros updates

Parking: find your domains by pasting a list
You can now paste a list of domain names into the search box at the top of the Parking menu. Put one name on each line. Your domain list...
AIVikings
Catchy
  • The sidebar remains visible by scrolling at a speed relative to the page’s height.
Back