| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153 |
- <?xml version="1.0" encoding="UTF-8"?>
- <!-- EN-Revision: 16394 -->
- <!-- Reviewed: no -->
- <sect2 id="zend.validate.set.in_array">
- <title>InArray</title>
- <para>
- <classname>Zend_Validate_InArray</classname> erlaubt es zu prüfen ob ein gegebener Wert
- in einem Array enthalten ist. Er ist auch in der Lage mehrdimensionale Arrays zu prüfen.
- </para>
- <sect3 id="zend.validate.set.in_array.basic">
- <title>Einfache Array Prüfung</title>
- <para>
- Der einfachste Weg ist es, das Array welches durchsucht werden soll, bei der
- Initiierung anzugeben:
- </para>
- <programlisting language="php"><![CDATA[
- $validator = new Zend_Validate_InArray(array('key' => 'value', 'otherkey' => 'othervalue'));
- if ($validator->isValid('value')) {
- // Wert gefunden
- } else {
- // Wert nicht gefunden
- }
- ]]></programlisting>
- <para>
- Das verhält sich genauso wie <acronym>PHP</acronym>'s
- <methodname>in_array()</methodname> Methode.
- </para>
- <note>
- <para>
- Standardmäßig ist diese Prüfung nicht strikt noch kann Sie mehrdimensionale Arrays
- prüfen.
- </para>
- </note>
- <para>
- Natürlich kann man das Array gegen das geprüft werden soll auch im Nachhinein durch
- Verwendung der <methodname>setHaystack()</methodname> Methode angegeben werden.
- </para>
- <programlisting language="php"><![CDATA[
- $validator = new Zend_Validate_InArray();
- $validator->setHaystack(array('key' => 'value', 'otherkey' => 'othervalue'));
- if ($validator->isValid('value')) {
- // Wert gefunden
- } else {
- // Wert nicht gefunden
- }
- ]]></programlisting>
- </sect3>
- <sect3 id="zend.validate.set.in_array.strict">
- <title>Strikte Array Prüfung</title>
- <para>
- Wie vorher erwähnt kann man auch eine Strikte Prüfung im Array durchführen.
- Standardmäßig würde kein Unterschied zwischen dem Integerwert <emphasis>0</emphasis>
- und dem String <emphasis>"0"</emphasis> sein. Wenn eine strikte Prüfung durchgeführt
- wird dann wird dieser Unterschied auch geprüft und nur gleiche Typen werden akzeptiert.
- </para>
- <para>
- Eine strikte Prüfung kann auch auf zwei verschiedenen Wegen durchgeführt werden. Bei
- der Initiierung und durch Verwendung einer Methode. Bei der Initiierung muß hierfür ein
- Array mit der folgenden Struktur angegeben werden:
- </para>
- <programlisting language="php"><![CDATA[
- $validator = new Zend_Validate_InArray(
- array(
- 'haystack' => array('key' => 'value', 'otherkey' => 'othervalue'),
- 'strict' => true
- )
- );
- if ($validator->isValid('value')) {
- // Wert gefunden
- } else {
- // Wert nicht gefunden
- }
- ]]></programlisting>
- <para>
- The <emphasis>haystack</emphasis> key contains your array to validate against, and by
- setting the <emphasis>script</emphasis> key to <constant>TRUE</constant> the validation
- is done by using a strict type check.
- </para>
- <para>
- Of course you can also use the <methodname>setStrict()</methodname> method to change
- this setting afterwards.
- </para>
- <note>
- <para>
- Note that the <emphasis>strict</emphasis> setting is per default
- <constant>FALSE</constant>.
- </para>
- </note>
- </sect3>
- <sect3 id="zend.validate.set.in_array.recursive">
- <title>Recursive array validation</title>
- <para>
- In addition to <acronym>PHP</acronym>'s <methodname>in_array()</methodname> method
- this validator can also be used to validate multidimensional arrays.
- </para>
- <para>
- To validate multidimensional arrays you have to set the <emphasis>recursive</emphasis>
- option.
- </para>
- <programlisting language="php"><![CDATA[
- $validator = new Zend_Validate_InArray(
- array(
- 'haystack' => array(
- 'firstDimension' => array('key' => 'value', 'otherkey' => 'othervalue'),
- 'secondDimension' => array('some' => 'real', 'different' => 'key')),
- 'recursive' => true
- )
- );
- if ($validator->isValid('value')) {
- // value found
- } else {
- // no value found
- }
- ]]></programlisting>
- <para>
- Your array will then be validated recursive to see if the given value is contained.
- </para>
- <note>
- <para>
- Note that per default the recursive validation is turned off.
- </para>
- </note>
- </sect3>
- </sect2>
- <!--
- vim:se ts=4 sw=4 et:
- -->
|