Unstoppable Domains โ€” Get your daily AI drops report

Extracting values out of a array

Namecheap AuctionsNamecheap Auctions
SpaceshipSpaceship
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
•••
Appraise.net
Escrow.com
Spaceship
Domain Recover
CryptoExchange.com
Catchy
DomDB
NameFit
  • The sidebar remains visible by scrolling at a speed relative to the pageโ€™s height.
Back