[registration] => Array
(
[first_name] => test
[location] => Array
(
[name] => Santa Ana
[id] => 1.08081209215E+14
)
[gender] => female
[password] => 123654789
)
and i need to insert that data into a database by using:
$carray = fns_create_talent($login, $pass, $gender, $name);
any idea on how to get them from a place to another?
i wa开发者_如何学Pythons thinking that i need to assign the array values to the post vars. maybe:
$login = registration.first_name...
any ideas? thanks
$login = $json['registration']['first_name']
What you have shown is not JSON, but PHP's array. I am assuming this is the structure of the data you want to be sent to the server.
You can do it like that (remember, there are no associative arrays in JavaScript!):
on Javascript side do something similar to this:
var data = { 'registration': { 'first_name': 'test', 'location': { 'name': 'Santa Ana', 'id': '1.08081209215E+14' }, 'gender': 'female', 'password': 123654789 } }
and then use
data
in eg. jQuery .post() as the second parameter.on the PHP side just read from
$_POST
as you read multi-dimensional associative arrays. In this case it should look similar to:// I have made assumption here (you do not have // 'login' variable in your example) $login = $_POST['registration']['first_name']; $pass = $_POST['registration']['password']; $gender = $_POST['registration']['gender']; $name = $_POST['registration']['first_name']; $carray = fns_create_talent($login, $pass, $gender, $name);
Here you go.
EDITED:
Where $arr is the array you submitted.
$carray = fns_create_talent(
/* your login var */,
$arr['registration']['password'],
$arr['registration']['gender'],
$arr['registration']['first_name']
);
I don't see your login inside the array, so I just put a comment for the login var, but you should get the idea.
精彩评论