sabelotodo: in_array x, y

Can someone help me with smarty syntax for "in_array"? I want to check if 2 variables in array:

{if in_array(($x,$y), $array)}var x and var y are in this array{/if}

is this syntax and or semantic right?

preguntado el 08 de noviembre de 11 a las 15:11

3 Respuestas

This is not an issue of "smarty syntax", but rather an issue of using the PHP function in_array correctly. Check out the documentation: http://php.net/manual/en/function.in-array.php

{if in_array($x, $array) && in_array($y, $array)}var x and var y are in this array{/if}

respondido 08 nov., 11:19

You need to call in_array for each variable to check:

{if in_array($x, $array) && in_array($y, $array)}var x and var y are in this array{/if}

respondido 08 nov., 11:19

You are attempting to check that both $x y $y tiene $array, so you need two conditions in your {if}

{if in_array($x, $array) && in_array($y, $array)}var x and var y are in this array{/if}

respondido 08 nov., 11:19

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.