Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
552 views
in Technique[技术] by (71.8m points)

how to pass an array in GET in PHP?

$idArray = array(1,2,3,4);

can I write this line in HTML?

<form method='POST' action='{$_SERVER['PHP_SELF']}?arr={$idArray}'>

or should I write:

<form method='POST' action='{$_SERVER['PHP_SELF']}?arr[]={$idArray}'>

how will it be passed?

how should I handle it in the called page?

thanks !!

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

If you want to pass an array as parameter, you would have to add a parameter for each element. Your query string would become:

?arr[]=1&arr[]=2&arr[]=3&arr[]=4

As others have written, you can also serialize and unserialize the array.

But do you really have to send the data to the client again? It looks like you just need a way to persist the data between requests.

In this case, it is better imo to use sessions(docs). This is also more secure as otherwise the client could modify the data.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...