Re: in_array() with multidimensional array
| From: | Chris Lee | Date: | Fri, 09 Mar 2001 14:52:16 +0000 |
| Subject: | Re: in_array() with multidimensional array | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-43171@lists.php.net to get a copy of this message | ||
recusrion is your friend.
<?php
$test[0][0] = 'a';
$test[0][1] = 'b';
$test[0][2] = 'c';
$test[1][0] = 'd';
$test[1][1] = 'e';
$test[1][2] = 'f';
$test[2][0] = 'g';
$test[2][1] = 'h';
$test[2][2] = 'i';
function in_multi_array($needle, $haystack)
{
foreach($haystack as $pos => $val)
{
if (is_array($val))
{
if (in_multi_array($needle, $val))
return 1;
} else
if ($val == $needle)
return 1;
}
}
if (in_multi_array('d', $test))
echo "TRUE <br>\n";
else
echo "FALSE <br>\n";
?>
--
Chris Lee
Mediawaveonline.com
ph. 250.377.1095
ph. 250.376.2690
fx. 250.554.1120
lee@mediawaveonline.com
""Christian Dechery"" <lemming@vento.com.br> wrote in message news:3AA690DE000003D9@webmail.vento.com.br...
How can I check if a value is in a multidimensional array?
like I have
<?php
$i=0;
while($idt = mssql_fetch_row($query_result))
{
//echo $idt[0]."<br>";
$produtos_sem_tracking[$i]['cod']=$idt[0];
$produtos_sem_tracking[$i]['idt']=$idt[1];
$produtos_sem_tracking[$i]['gen']=$idt[2];
}
?>
how can I check for an existing $produtos_sem_tracking['cod'] value for
example?
. [ Christian Dechery ]
. Webdeveloper @ Tá Na Mesa!
. Listmaster @ Gaita-L
. http://www.tanamesa.com.br
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net
For additional commands, e-mail: php-general-help@lists.php.net
To contact the list administrators, e-mail: php-list-admin@lists.php.net