You are here: Having problems with in_array function. « All PHP « IT news, forums, messages
Having problems with in_array function.

Posted by rich on 09/20/06 12:52

I have 2 arrays. I am trying to use in_array with and it doesn't seem
to be working. I have done a print_r of each one for my test data.

Array $primsecA is below:

Array ( [0] => Array ( [primsecid] => 1 [primsec] => Primary ) [1] =>
Array ( [primsecid] => 2 [primsec] => Secondary ) [2] => Array (
[primsecid] => 3 [primsec] => Skin Protectors ) )

Array $specprimA is below.
Array ( [0] => Array ( [primsecid] => 1 ) [1] => Array ( [primsecid] =>
2 ) )

Now here is the logic for checked fields.

$numcl= count($primsecA);
for ($i=0; $i<$numcl; $i++){

$primsec = $primsecA[$i]['primsec'];
$primsecid = $primsecA[$i]['primsecid'];
if (sizeof($specprimA)==0 || !is_array($specprimA)){?>
<input type="checkbox" tabindex="2" name="primsecid[]" value="<?php
echo $primsecA[$i]['primsecid']; ?>"/><?php echo $primsec;
}else{

if (in_array($primsecid, $specprimA)) { ?>
<input type="checkbox" checked="checked" tabindex="2"
name="primsecid[]" value="<?php echo $primsecA[$i]['primsecid'];
?>"/><?php echo $primsecA[$i]['primsec'];
} else { echo ?>

<input type="checkbox" tabindex="2" name="primsecid[]" value="<?php
echo primsecA[$i]['primsecid']; ?>"/><?php echo $primsec;

}
}
}?>

In the above code I want the field to be checked if its in the
$specprimA array. None of the fields are being checked. any ideas?

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация