473,386 Members | 1,873 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Have problems with in_array statement

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?

Sep 20 '06 #1
0 1065

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

12
by: AJ Z | last post by:
I am using in_array() to search for a value ("other"), in order to validate a form. If I pass $_POST as the array to search PHP says that it is an invalid datatype. It is an array and if I copy...
2
by: Mountain Man | last post by:
Hi, The in_array function sometimes malfunctions on my computer yielding the error message shown below. The code shown below usually works, but sometimes doesn't. This even happens with the same...
3
by: Phil Powell | last post by:
if (is_array($_POST)) { foreach ($this->getAssocSectionsObjArray($key, $dbAP) as $obj) { print_r($obj); print_r(" in array? "); print_r(in_array($obj, $result)); print_r("<P>"); if...
5
by: Phil Powell | last post by:
Here is my array. Plain and simple enumerative array with values being strings. So why does this fail??? print_r(in_array('album', array_keys($boolword))); This produces FALSE or NULL....
4
by: paul brown | last post by:
hello, I have this code sample: class Sexboard extends Master { var $userid; var $errormessage; var $dc_metro = array(20, 46, 51);
3
by: Tom Barnes | last post by:
Check out this code: // Start Code ------------- function test_in_array($val) { $a = array('key' => $val); printf("in_array: %d, value:%s<BR>", in_array('key', $a), $a); } test_in_array(0);...
6
by: Berimor | last post by:
Hi, i've been always used the in_array() function to check availabylity of a value in array. Until today. Simple code: (do not run it tho :) ) <? function getmicrotime(){ list($usec, $sec) =...
3
by: Sonnich | last post by:
The following code is an exact copy of my current code. The idea is to check 2 parts (of string arrays), and add those only once to a common array. I check for existance of an array in a string,...
3
by: GarryJones | last post by:
I want to add an value to an array if it is not already there. There are four values. Something is misfiring as it as the value to the array even if it is already there. The values are...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.