NameSilo

Extracting values out of a array

SpaceshipSpaceship
SpaceshipSpaceship
Namecheap AuctionsNamecheap Auctions
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.
Unstoppable Domains — AI StorefrontUnstoppable Domains — AI Storefront
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

We're social

Escrow.com
Spaceship
Escrowly
CryptoExchange.com
Domain Recover
URLs.com
  • The sidebar remains visible by scrolling at a speed relative to the page’s height.
Back