Re: Comparing string to array
| From: | Stut | Date: | Tue, 19 Jun 2007 16:48:56 +0000 |
| Subject: | Re: Comparing string to array | ||
| References: | 1 2 3 4 5 6 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-257438@lists.php.net to get a copy of this message | ||
Jim Lucas wrote:
Stut wrote:I thought I was pretty clear.Jim Lucas wrote:What do you mean?Richard Davey wrote:I'm not sure who's output you are referring to, but while you're making sense as a comment to a competely different question, it's not relevant to this question. -StutHi Jim, Tuesday, June 19, 2007, 5:06:47 PM, you wrote:in this case, it isn't a valid char. Look at his output, you will see that the single quotes are being included in the actual value of the submitted array. So, in this case, they will mess with his comparison. you'll be comparing "'bob'" not "bob" Look at the output a little closer...DON'T USE SINGLE QUOTES IN YOUR NAME="" ATTRIBUTEHate to piss on your bonfire but a single quote is a perfectly valid (if somewhat stupid choice of) character for inclusion in an array key. Cheers, Rich
This is the op's output
Array
(
[test] => Array
(
['bob'] => Array
(
[0] => red
[1] => green
[2] => blue
)
)
)
Do you see the single quotes in the array hey at the second level??
I do indeed.
They should not be there.Why not? They're in the form so they're in the post data. Seems reasonable to me.
it will mess with things.Only if you let it. Stand up to the quotes!! Fight for your rights!!
but, for the op here is what I think you might be looking for.
<pre>
<?php
$user = "sam";
if ( isset($_POST['test'][$user]) && count($_POST['test'][$user]) > 0 ) {
echo "yeah\n";
echo join(':', $_POST['test'][$user]);
}
else
{
echo 'nah';
}
?>
</pre>
<form method="post">
<input type="checkbox" name="test[bob][red]" value="red">red<br>
<input type="checkbox" name="test[bob][green]" value="green">green<br>
<input type="checkbox" name="test[bob][blue]" value="blue">blue<br>
<input type="checkbox" name="test[sam][red]" value="red">red<br>
<input type="checkbox" name="test[sam][green]" value="green">green<br>
<input type="checkbox" name="test[sam][blue]" value="blue">blue<br>
<input type="submit">
</form>
That's so far off the mark it's just not funny. As Richard has suggested, read the full thread otherwise you're never going to understand what the actual problem was.
-Stut
--
http://stut.net/