[advanced search]
 

Go Back   NamePros.com > Discussion > Web Design & Development > Programming

Programming PHP, Perl, Ruby on Rails, AJAX, HTML, XHTML, CSS, JavaScript, MySQL and any other coding topics.


Closed Thread
 
LinkBack Thread Tools
Old 08-25-2006, 04:41 AM   #1 (permalink)
New Member
 
Join Date: Jul 2006
Location: Punjab
Posts: 9
9.60 NP$ (Donate)

desibhupi is an unknown quantity at this point


Help! how to return an Array as return

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 Code:
$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
__________________
Gurdas Maan : The Legend
desibhupi is offline  
Old 08-25-2006, 05:52 AM   #2 (permalink)
Barru.
 
Barrucadu's Avatar
 
Join Date: Aug 2005
Location: East Yorkshire, England
Posts: 2,731
78.50 NP$ (Donate)

Barrucadu is a splendid one to beholdBarrucadu is a splendid one to beholdBarrucadu is a splendid one to beholdBarrucadu is a splendid one to beholdBarrucadu is a splendid one to beholdBarrucadu is a splendid one to beholdBarrucadu is a splendid one to behold


PHP Code:
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.
Barrucadu is offline  
Old 08-25-2006, 07:17 AM   #3 (permalink)
NamePros Member
 
Join Date: May 2006
Posts: 160
81.00 NP$ (Donate)

TwistMyArm is on a distinguished road


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.
TwistMyArm is offline  
Old 08-25-2006, 10:43 PM   #4 (permalink)
New Member
 
Join Date: Jul 2006
Location: Punjab
Posts: 9
9.60 NP$ (Donate)

desibhupi is an unknown quantity at this point


Quote:
Originally Posted by TwistMyArm
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
__________________
Gurdas Maan : The Legend
desibhupi is offline  
Closed Thread


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Site Sponsors
Advertise your business at NamePros

All times are GMT -7. The time now is 03:22 AM.


Powered by: vBulletin® Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0
Template-Modifications by TMS
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85