php mysql用数组更新值[关闭]

$array['a']['b']=50;
mysql_query("update table set name=name-$array['a']['b']");

It show's error. Why it is not working? How fix it?

Thanks

PHP's parser is not "greedy".

echo "$arr[a][b]"

is actually parsed as if it was:

echo $arr['a'];
echo '[b]';

and would produce as output

Array[b]

You need to use the {} notation for this to work as you've written it:

mysql_query("update table set name=name-{$array['a']['b']}");
                                        ^--              ^--

This should have more chances to work:

$array['a']['b'] = 50;

// concatenate instead of accessing the array element directly into the string
// + intval() to ensure that the query will be correct
// (supposing that name is an number field)
mysql_query("update table set name = name - ".intval($array['a']['b']));

Use the . operator to concatenate strings:

mysql_query("update table set name=name-" . $array['a']['b']);

try this:

mysql_query("update table set name='name-".$array['a']['b']."'");