Question

I have this module adding "packing stations" In "my account" i want to be able to change the users active station. Therefore i need to push the "userid" into selected "code".

My array when unserialized looks like:

Array
(
    [_1478435099391_391] => Array
        (
            [user] => 9
            [code] => #PACKINGSTATION 1
        )

    [_1478608807336_336] => Array
        (
            [user] => 100
            [code] => #PACKINGSTATION 2
        )

)

How can i push a new user into packingstation 2 forexample?

Was it helpful?

Solution

You can easily use core php function array_push . Suppose that you want to add new entry this array then you can easily do this like.

$test=unserialize($serialized_data);

if(is_array($test)){
array_push($test,$newData);
}

$serialized_data is your previous data.

Where $newData is new entry and it must be array. If its not array then you can easily convert into array by doing $newData=unserialize($serialized_data);

Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top