How to get data from this foreach loop

I’ve passed an array from one page to another using the GET method.
On the destination page, I retrieved the passing data and it looked like this:

<?php
	$str = "x[0]=this&x[1]=that";
	foreach (explode('&', $str) as $chunk) {
		$param = explode("=", $chunk);
		echo $param[1], '<br>'; // this , that
	}
?>

How do I use the data outside the foreach loop.
I want to do something like this:

<?php
	if ($x[0] == 'this' && $x[1] == 'that') {
		// do this
	} else {
		// do that
	}
?>

Thnaks,

Get parameters only accept strings so have a look at Php array functions, explode() and implode().

So, to be clear, you made the array into a string, passed it to another script via GET, and now want to manipulate it as though it’s an array?

If so, I suppose you’d want to reassemble it into an array, first?

Thanks with baffled,

I’ve a direction though.

Use Php implode() to convert the array to be passed to a string separated by a unique ascii character which is not in the array.

The receiving get parameter string is the used in the explode() back into an array.

@ketting00 you have an URL query string there. PHP has a dedicated function to parse that: parse_str()

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.