首页 > 解决方案 > 如何将数组值插入数据库

问题描述

我想知道如何将 'peter'、'paul'、'mary' 置换值插入 phpmyadmin 数据库。我的数据库 (id,name1,name2,name3) id 是自动递增的。

    <?php
    function pc_permute($items, $perms = array()) {
        if (empty($items)) { 
            echo join(' ', $perms) . "<br />";
       } else {
            for ($i = count($items) - 1; $i >= 0; --$i) {
             $newitems = $items;
             $newperms = $perms;
             list($foo) = array_splice($newitems, $i, 1);
             array_unshift($newperms, $foo);
             pc_permute($newitems, $newperms);
         }
    }
}

$arr = array('peter', 'paul', 'mary');

pc_permute($arr);

?>


1 peter paul mary
2 peter mary paul
3 paul peter mary
4 paul mary peter
5 mary peter paul
6 mary paul peter

标签: php

解决方案


推荐阅读