Jump to content

[SOLVED] How would I do this?


Unseeeen

Recommended Posts

So basically I have 2 lists of information.

 

ex:

list 1- bob, joe, dan, billy

list 2- paul, joe, jim, mike

 

After putting both of those lists into 2 text boxes, how would I make it so only the common ones show up? In this case joe would be the only name that should show up.

 

Thanks.

Link to comment
Share on other sites

Thanks guys, that helps a lot. Here's my code...

 

<form action="" method="post">
<textarea name="first"></textarea><br>
<textarea name="second"></textarea>
<input value="Submit" type="submit">

</form>
<?
$first = $_POST['first'];
$second = $_POST['second'];


$blah = explode(" ", $first);
$blahtwo = explode(" ", $second);

$result = array_intersect($blah, $blahtwo);
print_r($result);
?> 

 

It's simple, the way I like it. Anyways, how would I echo the info without having that "Array ( [0] => joe )" thing at the end?

Link to comment
Share on other sites

first use

$x=count($result); this count how many matches found

then loop

for($i=0; $1<$x; $i++)

{

    echo $result[$i];// assign in the variable

}

 

but if your sure that there will only be one match

echo $result[0]; this is how to replace the print_r

Link to comment
Share on other sites

I get an error with that...

 

Parse error: syntax error, unexpected T_LNUMBER, expecting T_VARIABLE or '$'

 

I don't really understand what that's trying to do anyways.

 

But what I mean by it annoys me, the result is in an array. I don't want it in an array.

Link to comment
Share on other sites

<form action="" method="post">
<textarea name="first"></textarea><br>
<textarea name="second"></textarea>
<input value="Submit" type="submit">

</form>
<?
$first = $_POST['first'];
$second = $_POST['second'];
$blah = explode(" ", $first);
$blahtwo = explode(" ", $second);

$result = array_intersect($blah, $blahtwo);
for($i=0; $i<count($result); $i++)
{
    echo $result[$i];// assign in the variable
}

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.