如何使用PHP计数词对(串)阵列插入到MySQL [英] How to using php count the word pair (string) array insert into MySQL

查看:97
本文介绍了如何使用PHP计数词对(串)阵列插入到MySQL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

双阵列的样品

$a=array("a","b","c","d");
$b=array("b","c","d","f");

和我使用的循环,产生这一结果

and I use for loop to produce this outcome

ab ac ad af bb bc bd bf cb cc cd cf db dc dd df

一个阵列美元的元素排列数组$ B的元素

one array $a element align an element of array $b

和我要计数的元素,这个解决方案
问题是我想BD和DB作为一个同样的事情,我们承认它出现两次
我怎么能做到这一点在PHP?
在那之后,我会记录所有的计数解决方案插入到MySQL

and I want to count the element to this solution the problem is I want bd and db as a same thing ,we recognize it appear two times how can i do it in php ? after that , I will record all the count solution insert into MySQL

推荐答案

快速解答 - 你的排序两个元素结合在一起,你在他们面前,然后检查他们的答案集已经存在

quick answer - sort your two elements before you combine them, then check if they already exist in the answer set.

$a=array("a","b","c","d");
$b=array("b","c","d","f");

$res = array();
foreach($a as $v1) {
  foreach($b as $v2) {
    $t = array($v1, $v2);
    asort($t);
    $val = implode('', $t);
    if(!in_array($val, $res))
      $res[] = $val;
  }
}
print_r($res);

这篇关于如何使用PHP计数词对(串)阵列插入到MySQL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆