array_unique显示错误数组到字符串的转换 [英] array_unique showing error Array to string conversion
问题描述
为了获得唯一值,我正在使用唯一值。下面是我正在使用的代码
For getting the unique values i am using unique values. Below is the code i am using
array_unique($results_external);
aasort($results_external,"created_on");
$returns_buy_external[]=array_reverse($results_external, true);
如果我使用这样的代码,以下是我得到的错误
If i use the code like this, below is the error i am getting
遇到PHP错误严重性:注意
A PHP Error was encountered Severity: Notice
消息:数组到字符串的转换
Message: Array to string conversion
文件名:models / product_model.php
Filename: models/product_model.php
行号:3550
3550行是array_unique($ results_external);
3550 line is array_unique($results_external);
任何人都可以帮助我,为什么会出现这样的错误以及如何解决它?
Can anyone help me, why it is getting error like this and how to solve it?
results_external样本格式如下
results_external sample format coming is below
Array
(
[0] => Array
(
[id] => 144
[name] => test
[slug] => test
[images] => {"9eebd0f69772dd3bdf8c787864437c85":{"filename":"9eebd0f69772dd3bdf8c787864437c85.png","alt":"TRESemme Smooth and Shine","caption":""}}
[track_stock] => 1
[seo_title] => ttt
[qty] => 0
[product_type] => 0
[price] => 0.00
[saleprice] => 0.00
[external_links] => http://test.com
[external_price] => 285.00
[external_saleprice] => 285.00
[created_on] => 2013-11-08 15:03:24
)
)
推荐答案
根据文档, array_unique
默认情况下将元素作为字符串进行比较。这意味着您的2D数组正在被转换为字符串数组(全部为 Array
并生成数组到字符串的通知),或者只能返回一个
As per the docs, array_unique
compares elements as strings by default. This means your 2D array is being converted to an array of strings (all being "Array"
and generating the array-to-string Notice) or which only one can be returned as unique.
使用 SORT_REGULAR
标志将元素按原样进行比较,但要注意,仅考虑数组如果它们具有相同的键值对,则等于。
Use the SORT_REGULAR
flag to compare the elements as they are, but be aware that arrays are only considered equal if they have the same key-value pairs.
示例:
print_r(array_unique($array, SORT_REGULAR));
这篇关于array_unique显示错误数组到字符串的转换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!