I have to pass an array value from one php page to another php page using <a href>
... here is my coding
$cluster
is an array
echo "<td><a href=myebon.php&cluster[]=".$cluster.">Click here to OFF</a></td>";
in myebon.php
$n=count($_GET[cluster]);
for($i=0;$i<=$n;$i++)
{
echo $cluster[$i]=$_GET['cluster'][$i];
}
The value is not accessible in the second page, it's displaying as array but not the values. I have tried serialization concept too ...
This is clear example code
first.php
<?php
$Mixed = array("1","2","3");
$Text = json_encode($Mixed);
$RequestText = urlencode($Text);
?>
<a href="second.php?cluster=<?php echo $RequestText; ?>">Click</a>
second.php
<?php
$Text = urldecode($_REQUEST['cluster']);
$Mixed = json_decode($Text);
print_r( $Mixed);
?>
I have checked, and it is working fine.
Use http_build_query
$data = array('foo', 'bar', 'lol');
echo '<a href="myebon.php?' . http_build_query(array('cluster' => $data)) . '">link</a>';
Output
<a href="myebon.php?cluster%5B0%5D=foo&cluster%5B1%5D=bar&cluster%5B2%5D=lol">link</a>
It can be retrieved with $_GET['cluster']
, e.g:
foreach ($_GET['cluster'] as $val) {
// my work here, example:
echo $val , "\n";
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With