How does php obtain the array in the variable and assign it to the variable?-php Tutorial

Source: Internet
Author: User
How does php obtain the array in the variable and assign it to the variable? PHPcode: How do I perform the following actions when $ products1001: (There is one execution statement) $ db-& gt; query (& quot; UPDATE {$ _ pre} contentSETstorages php how can I retrieve the array in the variable and assign the value to the variable?
PHP code
  How can I perform the following actions when $ products = 100 = 1: (one execution statement exists at this time) $ db-> query ("UPDATE {$ _ pre} content SET storage = storage-1 WHERE id = '000000 '"); how can I perform the following actions when $ products = 100 = 1,104 = 3: (two statements are executed at this time) $ db-> query ("UPDATE {$ _ pre} content SET storage = storage-1 WHERE id = '000000 '"); $ db-> query ("UPDATE {$ _ pre} content SET storage = storage-3 WHERE id = '000000 '"); when $ products = 100 = 1,104 = 8,204 = 4,243 = 2,690 = 1, how do I perform the following actions: (five statements are executed at this time) $ db-> query ("UPDATE {$ _ pre} content SET storage = storage-1 WHERE id = '000000 '"); $ db-> query ("UPDATE {$ _ pre} content SET storage = storage-8 WHERE id = '000000 '"); $ db-> query ("UPDATE {$ _ pre} content SET storage = storage-4 WHERE id = '000000 '"); $ db-> query ("UPDATE {$ _ pre} content SET storage = storage-2 WHERE id = '000000 '"); $ db-> query ("UPDATE {$ _ pre} content SET storage = storage-1 WHERE id = '000000 '");




------ Solution --------------------
PHP code
$products ='100=1,104=8,204=4,243=2,690=1';foreach(explode(',',$products) as $v){       $t=explode('=',$v);       $db->query("UPDATE {$_pre}content SET storage=storage-{$t[1]} WHERE id='{$t[0]}'");}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.