数组中同名的值 [英] Value with same name in Array
本文介绍了数组中同名的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想检查数组中是否有同名的值,如果有一个同名的值,我怎样才能得到它.假设我有
I want to check is there a value with same name in array, if there is a value with same name, how can i get it. Let's say i have
<?php
if (is_array(Yii::app()->session['cart_values']))
{
foreach ( Yii::app()->session['cart_values'] as $value) {
?>
接下来是什么,再次遍历另一个包含 $files 名称的数组,并检查是否存在同名文件.
and what is next, again go through another array which contain $files name and check it if there is file with same name.
我尝试了几个解决方案,但没有得到它.
I try few solutions but not get it.
谢谢
推荐答案
尝试这样的事情
<?php
if (is_array(Yii::app()->session['cart_values']))
{
foreach ( Yii::app()->session['cart_values'] as $values) {
// get the uniques (assuming that $values is an array)
$uniques = array_unique($values);
// get the common values on each arrays so you get the repeated values
$union = array_diff($values, $uniques);
}
}
?>
希望这会有所帮助.
这篇关于数组中同名的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文