NamePros
Welcome, Guest! Ready to make a name for yourself in the domain business? We welcome both the hobbyist and professional domainer to join the discussion as part of the NamePros community.

Click here to create your profile to start earning reputation for posting, and trader ratings for buying & selling in our free e-marketplace. Build your trader rating with each successful sale. Our system has tracked over 100,000 sales and counting!
FAQ & TOS Register Search Today's Posts Mark Forums Read

Go Back   NamePros.com > Website Development Discussion Forums > Programming
Reload this Page how to return an Array as return

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

Advanced Search


Closed Thread
 
LinkBack Thread Tools
Old 08-25-2006, 05:41 AM THREAD STARTER               #1 (permalink)
New Member
Join Date: Jul 2006
Location: Punjab
Posts: 9
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
????: NamePros.com http://www.namepros.com/programming/231364-how-to-return-an-array-return.html

$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, 06:52 AM   #2 (permalink)
Senior Member
 
Barrucadu's Avatar
Join Date: Aug 2005
Location: East Yorkshire, England
Posts: 2,689
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, 08:17 AM   #3 (permalink)
NamePros Member
Join Date: May 2006
Posts: 160
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, 11:43 PM THREAD STARTER               #4 (permalink)
New Member
Join Date: Jul 2006
Location: Punjab
Posts: 9
desibhupi is an unknown quantity at this point
 



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.
????: NamePros.com http://www.namepros.com/showthread.php?t=231364

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


Liquid Web Smart Servers  
All times are GMT -7. The time now is 05:07 AM.

Managed Web Hosting by Liquid Web
Domain name forum recommended by Domaining.com Powered by: vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.6.0 Ad Management plugin by RedTyger