2010-03-28 22:10:10 +00:00
|
|
|
<?xml version="1.0" encoding="utf-8"?>
|
2009-07-11 06:30:45 +00:00
|
|
|
<!-- $Revision$ -->
|
2007-06-20 22:25:43 +00:00
|
|
|
<refentry xml:id="function.array-udiff-uassoc" xmlns="http://docbook.org/ns/docbook">
|
2006-10-31 11:24:02 +00:00
|
|
|
<refnamediv>
|
|
|
|
<refname>array_udiff_uassoc</refname>
|
|
|
|
<refpurpose>Computes the difference of arrays with additional index check, compares data and indexes by a callback function</refpurpose>
|
|
|
|
</refnamediv>
|
2007-12-30 23:05:06 +00:00
|
|
|
<refsect1 role="description">
|
|
|
|
&reftitle.description;
|
2006-10-31 11:24:02 +00:00
|
|
|
<methodsynopsis>
|
|
|
|
<type>array</type><methodname>array_udiff_uassoc</methodname>
|
|
|
|
<methodparam><type>array</type><parameter>array1</parameter></methodparam>
|
|
|
|
<methodparam><type>array</type><parameter>array2</parameter></methodparam>
|
2013-09-24 13:06:51 +00:00
|
|
|
<methodparam choice="opt"><type>array</type><parameter>...</parameter></methodparam>
|
|
|
|
<methodparam><type>callable</type><parameter>value_compare_func</parameter></methodparam>
|
2012-03-12 05:55:59 +00:00
|
|
|
<methodparam><type>callable</type><parameter>key_compare_func</parameter></methodparam>
|
2006-10-31 11:24:02 +00:00
|
|
|
</methodsynopsis>
|
|
|
|
<para>
|
2007-12-30 23:05:06 +00:00
|
|
|
Computes the difference of arrays with additional index check, compares
|
|
|
|
data and indexes by a callback function.
|
|
|
|
</para>
|
|
|
|
<para>
|
2006-10-31 11:24:02 +00:00
|
|
|
Note that the keys are used in the comparison unlike
|
|
|
|
<function>array_diff</function> and <function>array_udiff</function>.
|
|
|
|
</para>
|
2007-12-30 23:05:06 +00:00
|
|
|
</refsect1>
|
|
|
|
<refsect1 role="parameters">
|
|
|
|
&reftitle.parameters;
|
|
|
|
<para>
|
|
|
|
<variablelist>
|
|
|
|
<varlistentry>
|
|
|
|
<term><parameter>array1</parameter></term>
|
|
|
|
<listitem>
|
|
|
|
<para>
|
|
|
|
The first array.
|
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
<varlistentry>
|
|
|
|
<term><parameter>array2</parameter></term>
|
|
|
|
<listitem>
|
|
|
|
<para>
|
|
|
|
The second array.
|
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
<varlistentry>
|
2013-09-24 13:06:51 +00:00
|
|
|
<term><parameter>value_compare_func</parameter></term>
|
2007-12-30 23:05:06 +00:00
|
|
|
<listitem>
|
|
|
|
<para>
|
2012-02-03 21:07:23 +00:00
|
|
|
&return.callbacksort;
|
2007-12-30 23:05:06 +00:00
|
|
|
</para>
|
2012-02-03 21:07:23 +00:00
|
|
|
&callback.cmp;
|
2007-12-30 23:05:06 +00:00
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
<varlistentry>
|
|
|
|
<term><parameter>key_compare_func</parameter></term>
|
|
|
|
<listitem>
|
|
|
|
<para>
|
|
|
|
The comparison of keys (indices) is done also by the callback function
|
|
|
|
<parameter>key_compare_func</parameter>. This behaviour is unlike what
|
|
|
|
<function>array_udiff_assoc</function> does, since the latter compares
|
|
|
|
the indices by using an internal function.
|
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
</variablelist>
|
|
|
|
</para>
|
|
|
|
</refsect1>
|
|
|
|
<refsect1 role="returnvalues">
|
|
|
|
&reftitle.returnvalues;
|
|
|
|
<para>
|
|
|
|
Returns an <type>array</type> containing all the values from
|
|
|
|
<parameter>array1</parameter> that are not present in any of the other
|
|
|
|
arguments.
|
|
|
|
</para>
|
|
|
|
</refsect1>
|
|
|
|
<refsect1 role="examples">
|
|
|
|
&reftitle.examples;
|
2006-10-31 11:24:02 +00:00
|
|
|
<para>
|
|
|
|
<example>
|
|
|
|
<title><function>array_udiff_uassoc</function> example</title>
|
|
|
|
<programlisting role="php">
|
2003-10-09 07:28:40 +00:00
|
|
|
<![CDATA[
|
|
|
|
<?php
|
|
|
|
class cr {
|
2004-01-22 12:55:24 +00:00
|
|
|
private $priv_member;
|
2006-10-31 11:24:02 +00:00
|
|
|
function cr($val)
|
2004-01-15 12:43:50 +00:00
|
|
|
{
|
2003-11-03 14:05:07 +00:00
|
|
|
$this->priv_member = $val;
|
|
|
|
}
|
2004-01-15 12:43:50 +00:00
|
|
|
|
2008-01-15 21:14:47 +00:00
|
|
|
static function comp_func_cr($a, $b)
|
2004-01-15 12:43:50 +00:00
|
|
|
{
|
2003-11-03 14:05:07 +00:00
|
|
|
if ($a->priv_member === $b->priv_member) return 0;
|
|
|
|
return ($a->priv_member > $b->priv_member)? 1:-1;
|
|
|
|
}
|
2006-10-31 11:24:02 +00:00
|
|
|
|
2008-01-15 21:14:47 +00:00
|
|
|
static function comp_func_key($a, $b)
|
2004-01-15 12:43:50 +00:00
|
|
|
{
|
2003-11-03 14:05:07 +00:00
|
|
|
if ($a === $b) return 0;
|
|
|
|
return ($a > $b)? 1:-1;
|
|
|
|
}
|
2003-10-09 07:28:40 +00:00
|
|
|
}
|
|
|
|
$a = array("0.1" => new cr(9), "0.5" => new cr(12), 0 => new cr(23), 1=> new cr(4), 2 => new cr(-15),);
|
2003-12-15 16:55:22 +00:00
|
|
|
$b = array("0.2" => new cr(9), "0.5" => new cr(22), 0 => new cr(3), 1=> new cr(4), 2 => new cr(-15),);
|
2003-10-09 07:28:40 +00:00
|
|
|
|
2003-12-15 16:55:22 +00:00
|
|
|
$result = array_udiff_uassoc($a, $b, array("cr", "comp_func_cr"), array("cr", "comp_func_key"));
|
2003-10-09 07:28:40 +00:00
|
|
|
print_r($result);
|
|
|
|
?>
|
2003-11-03 14:05:07 +00:00
|
|
|
]]>
|
2006-10-31 11:24:02 +00:00
|
|
|
</programlisting>
|
|
|
|
&example.outputs;
|
|
|
|
<screen>
|
2003-11-03 14:05:07 +00:00
|
|
|
<![CDATA[
|
2003-10-09 07:28:40 +00:00
|
|
|
Array
|
|
|
|
(
|
|
|
|
[0.1] => cr Object
|
|
|
|
(
|
|
|
|
[priv_member:private] => 9
|
|
|
|
)
|
|
|
|
|
|
|
|
[0.5] => cr Object
|
|
|
|
(
|
|
|
|
[priv_member:private] => 12
|
|
|
|
)
|
|
|
|
|
|
|
|
[0] => cr Object
|
|
|
|
(
|
|
|
|
[priv_member:private] => 23
|
|
|
|
)
|
|
|
|
)
|
|
|
|
]]>
|
2006-10-31 11:24:02 +00:00
|
|
|
</screen>
|
|
|
|
</example>
|
|
|
|
</para>
|
|
|
|
<simpara>
|
|
|
|
In our example above you see the <literal>"1" => new cr(4)</literal>
|
2009-04-16 20:12:03 +00:00
|
|
|
pair is present in both arrays and thus it is not in the output from the
|
2006-10-31 11:24:02 +00:00
|
|
|
function. Keep in mind that you have to supply 2 callback functions.
|
|
|
|
</simpara>
|
2007-12-30 23:05:06 +00:00
|
|
|
</refsect1>
|
|
|
|
<refsect1 role="notes">
|
|
|
|
&reftitle.notes;
|
2006-10-31 11:24:02 +00:00
|
|
|
<note>
|
|
|
|
<simpara>
|
|
|
|
Please note that this function only checks one dimension of a n-dimensional
|
|
|
|
array. Of course you can check deeper dimensions by using, for example,
|
|
|
|
<literal>array_udiff_uassoc($array1[0], $array2[0], "data_compare_func",
|
|
|
|
"key_compare_func");</literal>.
|
|
|
|
</simpara>
|
|
|
|
</note>
|
2007-12-30 23:05:06 +00:00
|
|
|
</refsect1>
|
|
|
|
<refsect1 role="seealso">
|
|
|
|
&reftitle.seealso;
|
2006-10-31 11:24:02 +00:00
|
|
|
<para>
|
2007-12-30 23:05:06 +00:00
|
|
|
<simplelist>
|
|
|
|
<member><function>array_diff</function></member>
|
|
|
|
<member><function>array_diff_assoc</function></member>
|
|
|
|
<member><function>array_udiff</function></member>
|
2008-01-15 21:18:35 +00:00
|
|
|
<member><function>array_udiff_assoc</function></member>
|
2007-12-30 23:05:06 +00:00
|
|
|
<member><function>array_intersect</function></member>
|
|
|
|
<member><function>array_intersect_assoc</function></member>
|
|
|
|
<member><function>array_uintersect</function></member>
|
|
|
|
<member><function>array_uintersect_assoc</function></member>
|
|
|
|
<member><function>array_uintersect_uassoc</function></member>
|
|
|
|
</simplelist>
|
2006-10-31 11:24:02 +00:00
|
|
|
</para>
|
|
|
|
</refsect1>
|
|
|
|
</refentry>
|
2003-10-09 07:28:40 +00:00
|
|
|
|
|
|
|
<!-- Keep this comment at the end of the file
|
|
|
|
Local variables:
|
|
|
|
mode: sgml
|
|
|
|
sgml-omittag:t
|
|
|
|
sgml-shorttag:t
|
|
|
|
sgml-minimize-attributes:nil
|
|
|
|
sgml-always-quote-attributes:t
|
|
|
|
sgml-indent-step:1
|
|
|
|
sgml-indent-data:t
|
|
|
|
indent-tabs-mode:nil
|
|
|
|
sgml-parent-document:nil
|
2009-09-25 07:04:39 +00:00
|
|
|
sgml-default-dtd-file:"~/.phpdoc/manual.ced"
|
2003-10-09 07:28:40 +00:00
|
|
|
sgml-exposed-tags:nil
|
|
|
|
sgml-local-catalogs:nil
|
|
|
|
sgml-local-ecat-files:nil
|
|
|
|
End:
|
|
|
|
vim600: syn=xml fen fdm=syntax fdl=2 si
|
|
|
|
vim: et tw=78 syn=sgml
|
|
|
|
vi: ts=1 sw=1
|
|
|
|
-->
|