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



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.
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()?

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
The problem is, I don't want to make changes to the function 'submit_post' because it is used all over the place, for posting (written by phpbb).

I tried constructing an array the way I mentioned but it bombed.  It seemed to work in some examples I read though...............
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.
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.
[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. 

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.