0

We have a multi-dimensional array which consists of the following model:

array( 0 => array('sfa' => 'sfb,'sfb' => 'aaaa,'sfc' => 'bbbb','sfd' => '10','sfe' => 'abc'), 1 => array('sfa' => 'sfb,'sfb' => 'aaaa,'sfc' => 'bbbb','sfd' => '10','sfe' => 'abc'), 2 => array('sfa' => 'sfb,'sfb' => 'aaaa,'sfc' => 'bbbb','sfd' => '10','sfe' => 'abc'), 3 => array('sfa' => 'sfb,'sfb' => 'aaaa,'sfc' => 'bbbb','sfd' => '10','sfe' => 'abc'), )

please note this is an example.

This information is stored in a session variable however for example this session is called a so the variable is $_SESSION['a']

i need to be able to change the $_SESSION data for $_SESSION['a'][0]['sfd'] from 10 to 100

i have already tried the following code:

$array = $_SESSION['a']; $quantity = 100; $replacements = array('sdf' => $quantity); array_replace($array[0],$replacements); var_dump($array);

But it won't work and it destroys the rest of the array aswel, I have tried but failed can anybody correct my mistake or give me a helping hand?

4

1 回答 1

0

我不确定我是否明白你的意思,但这就是你要找的吗?

if (isset($_SESSION['a'][0]['sfd'] ))
    $_SESSION['a'][0]['sfd'] =100;
于 2013-04-18T13:34:35.767 回答