Re: [PHP] Re: Comparing string to array

2007-06-19 Thread Richard Davey
Hi Al,

Tuesday, June 19, 2007, 1:46:47 PM, you wrote:

> preg_grep() or

> foreach($_POST as $value){

> if(empty($value)) continue;
> $good_stuff[] = $value;
> }

A classic case of not reading the post fully methinks.

Cheers,

Rich
-- 
Zend Certified Engineer
http://www.corephp.co.uk

"Never trust a computer you can't throw out of a window"

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] Re: Comparing string to array

2007-06-19 Thread Al

preg_grep() or

foreach($_POST as $value){

if(empty($value)) continue;
$good_stuff[] = $value;
}



Richard Davey wrote:

Hi all,

Ok it's 2am, my brain has gone to mush and I am having trouble
figuring out an easy way to do this, can anyone shed some light?

Take a peek at the following code:

// START


$userparam = "test['sam'][]";


//  How to check if $userparam exists in the $_POST array
//  and get all the values from it?

//  Obviously this won't work, but you get the idea:

if (isset($_POST[$userparam]))
{
echo 'yeah';
$values = $_POST[$userparam];
}
else
{
echo 'nah';
}
?>




red
green
blue
red2
green2
blue2




// END

From the code above I'm trying to figure out how to tell if the
$userparam exists in the $_POST array. PHP automatically expands the
form element name into multi-dim arrays within $_POST, so a simple
'isset' as shown in the code above won't play because it's got a
totally useless array key passed to it.

I need a way to turn the string:

"test['sam'][]"

into something I can look into $_POST for.

Any ideas? The coffee boost is wearing off, but I want to get this
licked tonight :-\

Cheers,

Rich


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php