|
Posted by GarryJones on 07/13/07 09:56
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
$ml_ept, $scfmlk1d, $scfmlk2d and $scfmlk3d
This is the code I am using to try and add only values that are not
already in the array
$konept=$ml_ept;
$arr_epst = array($konept);
$konept=$scfmlk1d;
include("chk_epst_arr.php");
$konept=$scfmlk1d;
include("chk_epst_arr.php");
$konept=$scfmlk1d;
include("chk_epst_arr.php");
Breakdown of that code
// First Value
$konept=$ml_ept;
// Create array with first value
$arr_epst = array($konept);
// Second value assigned
$konept=$scfmlk1d;
// .... and processed to see if it is already in the array
include("chk_epst_arr.php");
// Third value assigned
$konept=$scfmlk1d;
// .... and processed to see if it is already in the array
include("chk_epst_arr.php");
// Fourth value assigned
$konept=$scfmlk1d;
// .... and processed to see if it is already in the array
include("chk_epst_arr.php");
The process file "chk_epst_arr.php" that checks to see if it exits
contains the following code.
if (in_array($konept, $arr_epst)) {
echo 'already there<br>';
} else {
$arr_epst[] = $konept;
}
Breakdown of that and what I think it should be doing
// use of "if" to see if the new value is already in the array
if (in_array($konept, $arr_epst)) {
// if "yes" echo "already there and line break
echo 'already there<br>';
// close if and begin else
} else {
// if "no" add the new value
$arr_epst[] = $konept;
// close the else
}
As said, no matter if the value is already in the array or not it is
adding all four values to the array.
What am I missing?
Any help greatly appreciated
Garry Jones
Sweden
Navigation:
[Reply to this message]
|