简体   繁体   中英

Passing serialize Array to $_POST in PHP

I'm working with PHP and I trying to pass an array that is read with foreach , the array contains info by some users, I need pass this array to other view.

For example the $info_users has (username: 'Miguel', username: 'Angel')

In my first view I serialized the array: serialize($arrayUserData)

<?php
foreach($info_users as $users){
 echo "<p>".$users['username']."</p>";
}
|echo "<input type='hidden' name='ArrayUser' value='".serialize($users)."'/>";
?>

In my second view I unserialized the array: $var = unserialize($_POST['Array'])

<?php

$users = unserialize($_POST['Array']);
echo "<p>".$users['name']."</p>";

?>

The problem is that to show the info by the array just show the information to the last user(Angel) , but I need the info of the all users in the foreach(Miguel, Angel) .

serialize($infos_users["username"]); would take all the username of the array, not only the last.

In your unserialize, use a foreach too.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM