Re: how to ignore the first 2 items in this iteraction?



In article <jvd935dr2p6ie79dls54eddpkuespf7f0m@xxxxxxx>, gcox@xxxxxxxxxx
says...
On Sat, 13 Jun 2009 15:05:54 +0100, Geoff Berrow
<blthecat@xxxxxxxxxxx> wrote:

On Sat, 13 Jun 2009 08:24:11 -0400, Jerry Stuckle
<jstucklex@xxxxxxxxxxxxx> wrote:


foreach ($_POST as $value) {
$results .= $value . ",";
}
echo $results;
?>

How can I create $results so that the first 2 items are ignored?

Thanks

Geoff


Define "first two values". This is an associative array.

Indeed. What you need is an 'ignore' array.

<?php
//define items you want to ignore here
$ignore=array('first','second','submit');

$_POST['first'] = "1";
$_POST['second'] = "2";
$_POST['third'] = "fred";
$_POST['fourth'] = "jane";

foreach ($_POST as $key->$value) {
if(!in_array($key,$ignore)){
//using another array because we only want
//commas in between and not at the end
$results []= $value;
}

echo implode(",",$results);
?>

Untested.

Geoff

Thanks for your reply.

I am getting cannot access empty property error with

<?php
//define items you want to ignore here
$ignore=array('first','second','submit');

$_POST['first'] = "1";
$_POST['second'] = "2";
$_POST['third'] = "fred";
$_POST['fourth'] = "jane";

foreach ($_POST as $key->$value) {
if(!in_array($key,$ignore)){
//using another array because we only want
//commas in between and not at the end
$results []= $value;
}
}

echo implode(",",$results);
?>

any ideas?


Apologies if I'm completely wrong here, I'm fairly new to php and have
been lurking here for a couple of weeks to see what I can learn.

Anyway, should it be like this:

if(!in_array($key,$ignore)){
//using another array because we only want
//commas in between and not at the end
$results []= $value;
echo implode(",",$results);
}

Otherwise first time around nothing's been assigned to $results because
it would be 'ignored' in the if statement.

--
Pete Ives
Remove All_stRESS before sending me an email
.