在数组名称相同的价值 [英] 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) {
?>
和下一步是什么,再通过包含$文件名,并检查它是否存在具有相同名称的文件,另一个数组去了。
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.
感谢
推荐答案
尝试smething这样
Try smething like this
<?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屋!
查看全文