function.array-udiff-uassoc.html
14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<title>Ermittelt den Unterschied zwischen Arrays mit zusätzlicher Indexprüfung,
vergleicht Daten und Indizes mittels einer Callbackfunktion</title>
</head>
<body><div class="manualnavbar" style="text-align: center;">
<div class="prev" style="text-align: left; float: left;"><a href="function.array-udiff-assoc.html">array_udiff_assoc</a></div>
<div class="next" style="text-align: right; float: right;"><a href="function.array-udiff.html">array_udiff</a></div>
<div class="up"><a href="ref.array.html">Array Funktionen</a></div>
<div class="home"><a href="index.html">PHP Manual</a></div>
</div><hr /><div id="function.array-udiff-uassoc" class="refentry">
<div class="refnamediv">
<h1 class="refname">array_udiff_uassoc</h1>
<p class="verinfo">(PHP 5)</p><p class="refpurpose"><span class="refname">array_udiff_uassoc</span> — <span class="dc-title">Ermittelt den Unterschied zwischen Arrays mit zusätzlicher Indexprüfung,
vergleicht Daten und Indizes mittels einer Callbackfunktion</span></p>
</div>
<div class="refsect1 description" id="refsect1-function.array-udiff-uassoc-description">
<h3 class="title">Beschreibung</h3>
<div class="methodsynopsis dc-description">
<span class="type">array</span> <span class="methodname"><strong>array_udiff_uassoc</strong></span>
( <span class="methodparam"><span class="type">array</span> <code class="parameter">$array1</code></span>
, <span class="methodparam"><span class="type">array</span> <code class="parameter">$array2</code></span>
[, <span class="methodparam"><span class="type">array</span> <code class="parameter">$ ...</code></span>
], <span class="methodparam"><span class="type"><a href="language.pseudo-types.html#language.types.callback" class="type callback">callback</a></span> <code class="parameter">$data_compare_func</code></span>
, <span class="methodparam"><span class="type"><a href="language.pseudo-types.html#language.types.callback" class="type callback">callback</a></span> <code class="parameter">$key_compare_func</code></span>
)</div>
<p class="para rdfs-comment">
<span class="function"><strong>array_udiff_uassoc()</strong></span> gibt ein Array mit allen Werten von
<code class="parameter">array1</code>, welche in keinem der anderen Argumente
enthalten sind, zurück. Beachten Sie, dass Schlüssel anders als von
<span class="function"><a href="function.array-diff.html" class="function">array_diff()</a></span> und <span class="function"><a href="function.array-udiff.html" class="function">array_udiff()</a></span> für
den Vergleich herangezogen werden. Der Vergleich der Arrayinhalte wird
von der benutzerdefinierten Callbackfunktion
<code class="parameter">data_compare_func</code> durchgeführt. In dieser
Hinsicht ist das Verhalten anders als jenes von
<span class="function"><a href="function.array-diff-assoc.html" class="function">array_diff_assoc()</a></span>, welche eine eingebaute
Vergleichsfunktion verwendet. Der Vergleich der Schlüssel (Indizes) wird
von der Funktion <code class="parameter">key_compare_func</code> durchgeführt.
Dieses verhalten Unterschiedet sich von <span class="function"><a href="function.array-udiff-assoc.html" class="function">array_udiff_assoc()</a></span>
darin, dass Letztere die Indizes mit einer eingebauten Funktion vergleicht.
</p>
<p class="para">
<div class="example" id="example-4946">
<p><strong>Beispiel #1 <span class="function"><strong>array_udiff_uassoc()</strong></span> Beispiel</strong></p>
<div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB"><?php<br /></span><span style="color: #007700">class </span><span style="color: #0000BB">cr </span><span style="color: #007700">{<br /> private </span><span style="color: #0000BB">$priv_member</span><span style="color: #007700">;<br /> function </span><span style="color: #0000BB">cr</span><span style="color: #007700">(</span><span style="color: #0000BB">$val</span><span style="color: #007700">) <br /> {<br /> </span><span style="color: #0000BB">$this</span><span style="color: #007700">-></span><span style="color: #0000BB">priv_member </span><span style="color: #007700">= </span><span style="color: #0000BB">$val</span><span style="color: #007700">;<br /> }<br /><br /> function </span><span style="color: #0000BB">comp_func_cr</span><span style="color: #007700">(</span><span style="color: #0000BB">$a</span><span style="color: #007700">, </span><span style="color: #0000BB">$b</span><span style="color: #007700">) <br /> {<br /> if (</span><span style="color: #0000BB">$a</span><span style="color: #007700">-></span><span style="color: #0000BB">priv_member </span><span style="color: #007700">=== </span><span style="color: #0000BB">$b</span><span style="color: #007700">-></span><span style="color: #0000BB">priv_member</span><span style="color: #007700">) return </span><span style="color: #0000BB">0</span><span style="color: #007700">;<br /> return (</span><span style="color: #0000BB">$a</span><span style="color: #007700">-></span><span style="color: #0000BB">priv_member </span><span style="color: #007700">> </span><span style="color: #0000BB">$b</span><span style="color: #007700">-></span><span style="color: #0000BB">priv_member</span><span style="color: #007700">)? </span><span style="color: #0000BB">1</span><span style="color: #007700">:-</span><span style="color: #0000BB">1</span><span style="color: #007700">;<br /> }<br /> <br /> function </span><span style="color: #0000BB">comp_func_key</span><span style="color: #007700">(</span><span style="color: #0000BB">$a</span><span style="color: #007700">, </span><span style="color: #0000BB">$b</span><span style="color: #007700">) <br /> {<br /> if (</span><span style="color: #0000BB">$a </span><span style="color: #007700">=== </span><span style="color: #0000BB">$b</span><span style="color: #007700">) return </span><span style="color: #0000BB">0</span><span style="color: #007700">;<br /> return (</span><span style="color: #0000BB">$a </span><span style="color: #007700">> </span><span style="color: #0000BB">$b</span><span style="color: #007700">)? </span><span style="color: #0000BB">1</span><span style="color: #007700">:-</span><span style="color: #0000BB">1</span><span style="color: #007700">;<br /> }<br />}<br /></span><span style="color: #0000BB">$a </span><span style="color: #007700">= array(</span><span style="color: #DD0000">"0.1" </span><span style="color: #007700">=> new </span><span style="color: #0000BB">cr</span><span style="color: #007700">(</span><span style="color: #0000BB">9</span><span style="color: #007700">), </span><span style="color: #DD0000">"0.5" </span><span style="color: #007700">=> new </span><span style="color: #0000BB">cr</span><span style="color: #007700">(</span><span style="color: #0000BB">12</span><span style="color: #007700">), </span><span style="color: #0000BB">0 </span><span style="color: #007700">=> new </span><span style="color: #0000BB">cr</span><span style="color: #007700">(</span><span style="color: #0000BB">23</span><span style="color: #007700">), </span><span style="color: #0000BB">1</span><span style="color: #007700">=> new </span><span style="color: #0000BB">cr</span><span style="color: #007700">(</span><span style="color: #0000BB">4</span><span style="color: #007700">), </span><span style="color: #0000BB">2 </span><span style="color: #007700">=> new </span><span style="color: #0000BB">cr</span><span style="color: #007700">(-</span><span style="color: #0000BB">15</span><span style="color: #007700">),);<br /></span><span style="color: #0000BB">$b </span><span style="color: #007700">= array(</span><span style="color: #DD0000">"0.2" </span><span style="color: #007700">=> new </span><span style="color: #0000BB">cr</span><span style="color: #007700">(</span><span style="color: #0000BB">9</span><span style="color: #007700">), </span><span style="color: #DD0000">"0.5" </span><span style="color: #007700">=> new </span><span style="color: #0000BB">cr</span><span style="color: #007700">(</span><span style="color: #0000BB">22</span><span style="color: #007700">), </span><span style="color: #0000BB">0 </span><span style="color: #007700">=> new </span><span style="color: #0000BB">cr</span><span style="color: #007700">(</span><span style="color: #0000BB">3</span><span style="color: #007700">), </span><span style="color: #0000BB">1</span><span style="color: #007700">=> new </span><span style="color: #0000BB">cr</span><span style="color: #007700">(</span><span style="color: #0000BB">4</span><span style="color: #007700">), </span><span style="color: #0000BB">2 </span><span style="color: #007700">=> new </span><span style="color: #0000BB">cr</span><span style="color: #007700">(-</span><span style="color: #0000BB">15</span><span style="color: #007700">),);<br /><br /></span><span style="color: #0000BB">$result </span><span style="color: #007700">= </span><span style="color: #0000BB">array_udiff_uassoc</span><span style="color: #007700">(</span><span style="color: #0000BB">$a</span><span style="color: #007700">, </span><span style="color: #0000BB">$b</span><span style="color: #007700">, array(</span><span style="color: #DD0000">"cr"</span><span style="color: #007700">, </span><span style="color: #DD0000">"comp_func_cr"</span><span style="color: #007700">), array(</span><span style="color: #DD0000">"cr"</span><span style="color: #007700">, </span><span style="color: #DD0000">"comp_func_key"</span><span style="color: #007700">));<br /></span><span style="color: #0000BB">print_r</span><span style="color: #007700">(</span><span style="color: #0000BB">$result</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">?></span>
</span>
</code></div>
</div>
<div class="example-contents"><p>Das oben gezeigte Beispiel erzeugt folgende
Ausgabe:</p></div>
<div class="example-contents screen">
<div class="cdata"><pre>
Array
(
[0.1] => cr Object
(
[priv_member:private] => 9
)
[0.5] => cr Object
(
[priv_member:private] => 12
)
[0] => cr Object
(
[priv_member:private] => 23
)
)
</pre></div>
</div>
</div>
</p>
<p class="simpara">
In unserem Beispiel sehen Sie, dass das <em>"1" => new cr(4)</em>
Paar in beiden Arrays enthalten ist und daher nicht in der Ausgabe der
Funktion auftaucht. Denken Sie daran, dass Sie zwei Callbackfunktionen
angeben müssen.
</p>
<p class="simpara">
Für den Vergleich wird die benutzerdefinierte Funktion verwendet.
Diese muss einen Integer kleiner als, genau gleich oder
größer als Null zurückgeben, wenn das erste Argument entsprechend als
kleiner, gleich oder größer als das Zweite betrachtet wird.
</p>
<blockquote class="note"><p><strong class="note">Hinweis</strong>:
<span class="simpara">
Bitte beachten Sie, dass diese Funktion nur eine Dimension eines
n-dimensionalen Arrays überprüft. Natürlich können Sie tiefere Dimensionen
prüfen, indem Sie
<em>array_udiff_uassoc($array1[0], $array2[0], "data_compare_func",
"key_compare_func");</em> verwenden.
</span>
</p></blockquote>
<p class="para">
Siehe auch
<span class="function"><a href="function.array-diff.html" class="function">array_diff()</a></span>,
<span class="function"><a href="function.array-diff-assoc.html" class="function">array_diff_assoc()</a></span>,
<span class="function"><a href="function.array-diff-uassoc.html" class="function">array_diff_uassoc()</a></span>,
<span class="function"><a href="function.array-udiff.html" class="function">array_udiff()</a></span>,
<span class="function"><a href="function.array-udiff-assoc.html" class="function">array_udiff_assoc()</a></span>,
<span class="function"><a href="function.array-intersect.html" class="function">array_intersect()</a></span>,
<span class="function"><a href="function.array-intersect-assoc.html" class="function">array_intersect_assoc()</a></span>,
<span class="function"><a href="function.array-uintersect.html" class="function">array_uintersect()</a></span>,
<span class="function"><a href="function.array-uintersect-assoc.html" class="function">array_uintersect_assoc()</a></span> und
<span class="function"><a href="function.array-uintersect-uassoc.html" class="function">array_uintersect_uassoc()</a></span>.
</p>
</div>
</div><hr /><div class="manualnavbar" style="text-align: center;">
<div class="prev" style="text-align: left; float: left;"><a href="function.array-udiff-assoc.html">array_udiff_assoc</a></div>
<div class="next" style="text-align: right; float: right;"><a href="function.array-udiff.html">array_udiff</a></div>
<div class="up"><a href="ref.array.html">Array Funktionen</a></div>
<div class="home"><a href="index.html">PHP Manual</a></div>
</div></body></html>