codeigniter - Geting php error for array_merge and array_unique -
below arrays , code trying unique/merge
$data['default_new'] = array_unique(array_merge($data['default'], $data['related'])) array ( [0] => array ( [keywords_id] => 8 [keyword] => curling [parent_id] => 5 [count] => 0 ) ) array ( [0] => array ( [keywords_id] => 8 [keyword] => curling [parent_id] => 5 [count] => 0 ) [1] => array ( [keywords_id] => 10 [keyword] => catchers [parent_id] => 6 [count] => 0 ) [2] => array ( [keywords_id] => 16 [keyword] => ces 2013 [parent_id] => 3 [count] => 0 ) )
it gives me array string error:
a php error encountered severity: notice message: array string conversion filename: models/content_model.php line number: 29
i had problem unique , merge before , never fixed it!
i using codeigniter
here more info regarding function using array_unique/merge in:
public function results($data, $searched) { $page['searched'] = $searched; $page['is_active'] = $this->logic_model->is_active(); $data2 = array(); $data2['default_new'] = array_unique(array_merge($data['default'], $data['related'])); }
line 29 $data2['default_new'] = array_u
the $data
parameter contains, default
, regular
can seen above.
vardump of data:
array(3) { ["active"]=> array(2) { ["id"]=> string(1) "5" ["keyword"]=> string(6) "sports" } ["related"]=> array(1) { [0]=> array(4) { ["keywords_id"]=> string(1) "8" ["keyword"]=> string(7) "curling" ["parent_id"]=> string(1) "5" ["count"]=> string(1) "0" } } ["default"]=> array(3) { [0]=> array(4) { ["keywords_id"]=> string(1) "8" ["keyword"]=> string(7) "curling" ["parent_id"]=> string(1) "5" ["count"]=> string(1) "0" } [1]=> array(4) { ["keywords_id"]=> string(2) "10" ["keyword"]=> string(8) "catchers" ["parent_id"]=> string(1) "6" ["count"]=> string(1) "0" } [2]=> array(4) { ["keywords_id"]=> string(2) "16" ["keyword"]=> string(8) "ces 2013" ["parent_id"]=> string(1) "3" ["count"]=> string(1) "0" } } }
take @ notes section here: http://us.php.net/array_unique#refsect1-function.array-unique-notes
you're going need come own algorithm creating unique multidimensional array. of comments @ link above suggest various methods accomplishing this, e.g., this one:
<?php $values = array(); foreach($data $d) { $values[md5(serialize($d))] = $d; } sort($values); ?>
related questions on so: strange behavior of php array_unique , how use array_unique on array of arrays?
Comments
Post a Comment