» Quick Links
You can make money on these forums
We Share profits with you
Google
Google Adsense
Google Adwords
YPN
Yahoo
MSN Search
Web Directories
Web Hosting
Web Hosting Offers
Hosting News
Suggestions
Link Building
Domain Names
PHP Forums
MySQL Forums
» More Links
OSP News
Reseller Hosting
Shared Hosting
Dedicated Servers
Google Adsense
Search Engine Marketing
Link Development
Affiliate Marketing


» Advertising
Multiple DC PR Check

Free SEO Tools


Go Back   Webmaster Forums > Website Developement / Programming > PHP Programming and Tips

PHP Programming and Tips Discuss about PHP programming and Share Tips. Ask questions about Scripting and Errors.

Reply
 
Thread Tools Display Modes
  #1  
Old 08-11-2006, 01:17 PM
benaud benaud is offline
Junior Member
 
Join Date: Aug 2006
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Rep Power: 0
benaud is on a distinguished road
Default way to merge Hash (Array) dynamically?

I want to store key and values in one array. I am getting values through POST method.. If i get value then store in hash.. else not..

suppose

PHP Code:
<?php
$values=array // HASH ARRAY //
if($_POST['name']) { ('name'=>$_POST['name']);
if($_POST['email']) { ('email'=>$_POST['email']);
if($_POST['phone']) { ('phone'=>$_POST['phone']);

// How to create associative array for this type of condition ???? //
?>


I hope, you understand now, what i mean?? How to push above values in Associative array ?? (If i found value then and then it should be push else not) -- This message may have been cut off and the rest will only be shown to members. To become a member, click here --
Reply With Quote
Revenue Sharing Ads ( ?):
  #2  
Old 08-11-2006, 01:19 PM
jackman jackman is offline
OSP Starters
 
Join Date: Jul 2006
Posts: 12
Thanks: 0
Thanked 0 Times in 0 Posts
Rep Power: 0
jackman is on a distinguished road
Default

Hi benaud
Try this code

# initialize
$values = array();

# if its set, set it(!) otherwise, leave the hash empty
$values['name'] = isset($_POST['name']) ? validate_function($_POST['name']) : '';

I hope it is working fine now -- This message may have been cut off and the rest will only be shown to members. To become a member, click here --
Reply With Quote
  #3  
Old 08-11-2006, 01:21 PM
monty monty is offline
OSP Starters
 
Join Date: Jul 2006
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Rep Power: 0
monty is on a distinguished road
Default

Another way of doing it is

PHP Code:
# initialize
$values = array();

# set and not empty?
if (isset($_POST['name']) && !empty($_POST['name'])
{
# set it!
$values['name'] = $_POST['name'];
}
else
{
# error_handler
}
# you could then loop through $_POST with one of the above,
# and if the $_POST key is in your allowed key range, set it
# to your new array (presumably for creating a sanitized way
# of accessing the data)

A bit more verbose version -- This message may have been cut off and the rest will only be shown to members. To become a member, click here --
Reply With Quote
Reply


Thread Tools
Display Modes

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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
hash index support? Lea MySQL Forums 1 02-27-2007 08:08 AM
MERGE tables issue! Tyamini MySQL Forums 1 02-09-2007 06:36 AM
merge MyIsam?? qasif MySQL Forums 1 10-17-2006 04:14 AM
Welcome to array on OutSourcingPlans... osp Introductions 0 07-18-2006 02:22 PM
Unable to Assign in an Array !! jackky PHP Programming and Tips 1 12-09-2005 05:03 AM


All times are GMT. The time now is 08:41 PM.