Hi everyone!
I seem to have a problem creating an array. I have a form which reads a csv file and needs to put those values in an array in order to fill a form.
when i use the following code:
$itemline = array
(
$key => array
(
"crt" => $crt,
"pcs" => $pcs,
"originalpcs" => $originalpcs,
));
// 1905_B0301C is used as a test key (key is valid)
echo $itemline["1905_B0301C"]["pcs"].";";
echo $itemline["1905_B0301C"]["crt"].";";
echo $itemline["1905_B0301C"]["originalpcs"]."<br>";
The following error occurs
Notice: Undefined index: 1905_B0301C in C:\www\arraytest.php on line 48
;
Notice: Undefined index: 1905_B0301C in C:\www\arraytest.php on line 49
;
Notice: Undefined index: 1905_B0301C in C:\www\arraytest.php on line 50
When i use a static key:
$itemline = array
(
"1905_B0301C" => array
(
"crt" => $crt,
"pcs" => $pcs,
"originalpcs" => $originalpcs,
));
It does return the right values:
50;2;50
Cant i use my $key as key in an array or am i doing something else wrong ?
Just in case, here is my whole test code:
if (file_exists("temp/pick_temp.txt")) {
$fh = fopen("temp/pick_temp.txt", "r");
while (!feof($fh)) {
$line = fgets($fh);
$pos = strpos($line, ';');
$item = substr($line, 0, $pos);
$reststring = substr($line, $pos+1);
$pos = strpos($reststring, ';');
$position = substr($reststring, 0, $pos);
$reststring = substr($reststring, $pos+1);
$pos = strpos($reststring, ';');
$crt = substr($reststring, 0, $pos);
$reststring = substr($reststring, $pos+1);
$pos = strpos($reststring, ';');
$pcs = substr($reststring, 0, $pos);
$reststring = substr($reststring, $pos+1);
$originalpcs = $reststring;
$key=$item."_".$position;
If ($item != '') {
$itemline = array
(
$key => array
(
"crt" => $crt,
"pcs" => $pcs,
"originalpcs" => $originalpcs,
));
}
}
fclose($fh);
echo $itemline["1905_B0301C"]["pcs"].";";
echo $itemline["1905_B0301C"]["crt"].";";
echo $itemline["1905_B0301C"]["originalpcs"]."<br>";
}