php 二维数组比较用,谁能给写个可以随时调用的功能出来。
old=Array([0]=>Array([.id]=>*1[name]=>clinic[password]=>cinilc)}new=Array([0]=>Array(...
old = Array
(
[0] => Array
(
[.id] => *1
[name] => clinic
[password] => cinilc
)
}
new = Array
(
[0] => Array
(
[name] => admin
[birthday] => 19999999
)
}
if admin not in new then
do delete//我自己写代码
if clinic not in old then
do add//我自己写代码
帮忙写一个founction,如下调用就可以。
compare($username) 展开
(
[0] => Array
(
[.id] => *1
[name] => clinic
[password] => cinilc
)
}
new = Array
(
[0] => Array
(
[name] => admin
[birthday] => 19999999
)
}
if admin not in new then
do delete//我自己写代码
if clinic not in old then
do add//我自己写代码
帮忙写一个founction,如下调用就可以。
compare($username) 展开
展开全部
// 给个思路
function compare($username){
$old = Array(
[0] => Array(
['id'] => '*1',
['name'] => 'clinic',
['password'] => 'cinilc'
)
);
$new = Array(
[0] => Array(
['name'] => 'admin',
['birthday'] => '19999999'
)
);
// 由于old ,new 是二维数组,需循环
foreach ($old as $key => $value) {
if (in_array($value, $username)) {
echo 'username 在old 中';
}
}
foreach ($new as $key => $value) {
if (in_array($value, $username)) {
echo 'username new 中';
}
}
}
function compare($username){
$old = Array(
[0] => Array(
['id'] => '*1',
['name'] => 'clinic',
['password'] => 'cinilc'
)
);
$new = Array(
[0] => Array(
['name'] => 'admin',
['birthday'] => '19999999'
)
);
// 由于old ,new 是二维数组,需循环
foreach ($old as $key => $value) {
if (in_array($value, $username)) {
echo 'username 在old 中';
}
}
foreach ($new as $key => $value) {
if (in_array($value, $username)) {
echo 'username new 中';
}
}
}
更多追问追答
追问
如果还要通过对比出的结果取其它信息呢,比如 id
追答
//直接输出就行了,要返回的话就 return
foreach ($old as $key => $value) {
if (in_array($value, $username)) {
echo 'username 在old 中';
echo $value['id'];
echo $value['password'];
//输出的信息就是username 所在的那个数组里面的信息
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询