Home > Backend Development > PHP Tutorial > php怎么取得变量中的数组并赋值到变量中

php怎么取得变量中的数组并赋值到变量中

WBOY
Release: 2016-06-13 13:18:39
Original
734 people have browsed it

php如何取得变量中的数组并赋值到变量中?

PHP code
<!--

Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/

-->        当 $products = 100=1时        
        我怎么执行以下动作:(此时有 1 个执行语句) 
        
        运行时是这样的   $db->query("UPDATE {$_pre}content SET storage=storage-1 WHERE id='100'");

        
        
        
        当 $products = 100=1,104=3 时        
        我怎么执行以下动作:(此时有 2 个执行语句)  
        
        运行时是这样的   $db->query("UPDATE {$_pre}content SET storage=storage-1 WHERE id='100'");
                         $db->query("UPDATE {$_pre}content SET storage=storage-3 WHERE id='104'");
            
        
        当 $products = 100=1,104=8,204=4,243=2,690=1 时        
        我怎么执行以下动作:(此时有 5 个执行语句)  
        
        运行时是这样的   $db->query("UPDATE {$_pre}content SET storage=storage-1 WHERE id='100'");
                         $db->query("UPDATE {$_pre}content SET storage=storage-8 WHERE id='104'");
                         $db->query("UPDATE {$_pre}content SET storage=storage-4 WHERE id='204'");
                         $db->query("UPDATE {$_pre}content SET storage=storage-2 WHERE id='243'");
                         $db->query("UPDATE {$_pre}content SET storage=storage-1 WHERE id='690'");
Copy after login




------解决方案--------------------
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]}'");
} <div class="clear">
                 
              
              
        
            </div>
Copy after login
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template