Jump to content

[SOLVED] Passing a variable (with variables in it) to a function


jeffery1493

Recommended Posts

Hi All,

I wonder if this is possible to do.  What I have is a PHP function that is being called with a bunch of arguments like this:

submit_post($name, $address, $city, $state, $zip);

What I want to do is put $name $address $city $state $zip all into one string:

$user_info = "'" . $name . "','" . $address . "','" . $city . "','" $state . "','" . $zip . "'";




I can then put $user_info into a $_SESSION variable, and pass it among many different web pages.
When I get to the last page, I could then do this:


submit_post ($user_info)
and run the function on all the info that was entered many pages ago.

Does this make sense???
It doesn't work the way I did it (obviously..........)    Thanks if anybody has done something like this before....

JEFFERY1493



Link to comment
Share on other sites

You may need two functions to do this, or to make the argument an array rather than a string and several strings.
You have it accepting 5 arguments one place, then 1 another, you seem to want two different functions. Just make two different functions.
Link to comment
Share on other sites

I don't understand the two functions idea, but make an array.......I never thought of that!


The thing is, the submit_post is a PHPBB function that submits posts (like the one used to power this forum).  I don't want to mess with that.

What I am doing is taking all the user info when they enter a post, and then setting it aside.  Then you go through several web pages where you make a payment.  If the payment succeeds, then I want to run submit_post with the info you entered a long time ago.

Say you put all the info into an array........how would you refer to it in submit_post()?

Link to comment
Share on other sites

I prefer associative arrays myself, because I don't think in numbers.... So I would do it like so.

$user_data=array("name"=>"$name", "address"=>"$address", "city"=>"$city")

Then you can pass the $user_data array into the function and inside the function use a specific piece by associative array name

submit_post($user_data)

$user_data['name'];
$user_data['address'];
$user_data['city'];

@simcoweb --- I would not PM Jesirose unless she has allowed you to do so, She got pissed at another person doing this tonight. Read the rules
Link to comment
Share on other sites

create your array like this,


[code]$user_data=array("name"=>"$name", "address"=>"$address", "city"=>"$city", "state=>"$state", "zip=>"$zip")[/code]


pass the pieces of the array into the function like this.

[code]submit_post($user_data['name'] , $user_data['address'], $user_data['city'] , $user_data['state'], $user_data['zip'])[/code]


Essentially it is exactly the same as

[code]submit_post($name, $address, $city, $state, $zip);[/code]

except that your using array pieces instead of straight variables.
Link to comment
Share on other sites

Thanks for the heads up, Chronister. Jesirose and I have indeed exchanged PM's before. However, it's not appearing to go through to her. Not sure why. I'm 100% certain, though, that it wasn't something belligerent or against the rules :)  We discussed some work.
Link to comment
Share on other sites

[quote author=simcoweb link=topic=124831.msg517838#msg517838 date=1170227540]
that it wasn't something belligerent or against the rules
[/quote]

It's against the rules. Don't PM members with requests for help, for two reasons. One: Your problem has the same priority as every other problem. We'll help you if and when we want to. Two: Solutions determined via PM are useless to the community. Nobody can benefit from a solution that they can't see. 
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.