Dynadot .com transfer sale, only $10.12 with coupon code DYNA12, available while supplies last, ends October 31, 2026.

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.
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
•••
AIVikingsAIVikings

We're social

Escrow.com
Spaceship
Escrowly
CryptoExchange.com
Domain Recover

NamePros updates

New in Parking: updated way to act on many domains or inquiries at once
Your domain list and inquiry list now have a bar above and below the list. Check the items you want, then choose an action in the bar...
AIVikings
Catchy
  • The sidebar remains visible by scrolling at a speed relative to the page’s height.
Back