Unstoppable Domains โ€” Expired Auctions

Extracting values out of a array

SpaceshipSpaceship
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.
AfternicAfternic
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
•••
CatchedCatched
Escrow.com
Spaceship
Rexus Domain
CryptoExchange.com
Domain Recover
CatchDoms
NameMaxi - Your Domain Has Buyers
DomDB
  • The sidebar remains visible by scrolling at a speed relative to the pageโ€™s height.
Back