storing php objects on html form element and passing php objects through GET method?

前端 未结 3 1979
独厮守ぢ
独厮守ぢ 2020-12-29 00:43

I might sound a bit weird but, is there a way? For example, I have a PHP object $foo.

Is there a way to store this object in an HTML form (hidden input)

3条回答
  •  时光取名叫无心
    2020-12-29 01:08

    You can use the serialize and unserialize methods:

    $serialized = serialize($foo);
    

    Now you can store $serialized in your hidden input field. Later, you can read it back and convert to object with unserialize method. For example:

    $foo = unserialize($_POST['my_hidden_field']); // back to object
    

提交回复
热议问题