NOVINKA: Kurz kybernetickej bezpečnosti teraz už od 0 €. Staň sa žiadaným profesionálom. Zisti viac:
NOVINKA: Staň sa dátovým analytikom od 0 € a získaj istotu práce, lepší plat a nové kariérne možnosti. Viac informácií:

PHP - serialize

Trieda

Koreň \ Bez triedy

Metóda - serialize

(PHP 4, PHP 5, PHP 7)

The function generates a textual representation of a value which is suitable to be stored. It handles all data types except the resource type. It's possible to recreate the original value from the serialized value later.

Procedurálne

Parametre

NázovDátový typPredvolená hodnotaPopis
$valuemixed

The value to be serialized.

Mávratovej hodnoty

Vracia: string

Returns a string representation of a value which is suitable to be stored.

Note: When saving this value into the database , it's better to use the BLOB type rather than CHAR or TEXT.

Príklady

Serialization and deserialization of class instance:

<?php
class Dog
{
    private $name;

    public function __construct($name)
    {
        $this->name = $name;
    }

    public function sayHello()
    {
        echo 'Woof woof! I am ' . $this->name . '!';
    }
}

$dog = new Dog('Bad');

$packed = serialize($dog);
echo $packed . "\n";

$unpacked = unserialize($packed);
$unpacked->sayHello();

Serialization of array:

$animals = ['Dog', 'Cat', 'Rabbit', 'Mouse'];
echo serialize($animals);

Súvisiace manuály

      • function json_encode (mixed $value, int $depth = 512) : string
      Aktivity