Page 1 of 1

array match problem

Posted: Sat Jun 07, 2008 1:01 am
by wilsonee
Hi,

I'm using a form to create an array and need to pass array to PHP to check if there is a matching field.

if($_POST['add']) {
...
$apple= $_POST['xxx'];
$oranges= $_POST['yyy'];

I create an array

$myarray = array("first => $apple","second => $oranges");

I read a file that contains similar entries as $myarray.

$row = 1;
$handle = fopen("file","r");
while(($data = fgetcsv($handle, 1000, " = ")) !== FALSE) {
...

I need to search through this array and alert if there's a match.
eg. if "$apple" exists in the file and also in $myarray.

I'm using foreach($myarray as $k => $v) {
...

but it looks like I get a value that is a concatenation of array elements not separated.
eg. first $apple second $oranges
How can I do this, please help.

Re: array match problem

Posted: Sat Jun 07, 2008 3:57 am
by madan koshti
Hi,
$myarray = array("first => $apple","second => $oranges"); this will create an array like array ( [0] => first => apple [1] => second => oranges )

If you want array with keys 'first' and value as 'apple' then use this :
$myarray = array("first" => $apple,"second" => $oranges);

Hope it will be usefull .