array match problem

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
wilsonee
Forum Newbie
Posts: 7
Joined: Fri Jun 06, 2008 10:42 pm

array match problem

Post 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.
madan koshti
Forum Commoner
Posts: 50
Joined: Fri Jun 06, 2008 4:25 am

Re: array match problem

Post 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 .
Post Reply