NameSilo

Extracting values out of a array

Spaceship Spaceship
Watch

H-O-V

Established Member
Impact
2
I have an array of values from a form ($_POST) and they are all checkboxes so

carrots => on
apples =>

etc

is there any way of selecting just the on ones in another array?
 
0
•••
The views expressed on this page by users and staff are their own, not those of NamePros.
GoDaddyGoDaddy
How do you want them to be selected? If you are going to loop through and do something to each one anyways, you don't really need any extra code.

PHP:
foreach ($_POST as $key => $value)
{
	if ($value == "on")
	{
		// do something.
	}
}
 
0
•••
Dan's solution will work 100% although another way of doing it would be like:-

PHP:
<?php
$_POST = array('banana'=>'on','orange'=>'on','grapefruit'=>'off','lettuce'=>'on');

function check_on($setting, $fruit)
{
	if ($setting == 'on')
	{
		echo $fruit.' is on</br>';
	}
}

array_walk($_POST, 'check_on');
?>
 
0
•••
Dynadot — .com Registration $8.99Dynadot — .com Registration $8.99
Appraise.net

We're social

Unstoppable Domains
Domain Recover
DomainEasy — Zero Commission
  • The sidebar remains visible by scrolling at a speed relative to the page’s height.
Back