[ create a new paste ] login | about

Link: http://codepad.org/MKQP1fXf    [ raw code | output | fork ]

PHP, pasted on Oct 1:
<?php
$array = array(
	array(
		'id' => 1,
		'price1' => 16,
		'price2' => 10,
		'price3' => 3
	),
	array(
		'id' => 2,
		'price1' => 19,
		'price2' => 2,
		'price3' => 6
	),
	array(
		'id' => 3,
		'price1' => 14,
		'price2' => 32,
		'price3' => 1
	)
);


foreach($array as $item)
{
	$lowestKey = '';
	foreach($item as $key => $value)
	{
		if(strpos($key, 'price') === 0)
		{
			if($lowestKey == '')
			{
				$lowestKey = $key;
			}
			else
			{
				if($value < $item[$lowestKey])
				{
					$lowestKey = $key;
				}
			}
		}
	}
	
	echo 'lowest for id ' . $item['id'] . ': ' . $item[$lowestKey] . "\n";
}


Output:
1
2
3
lowest for id 1: 3
lowest for id 2: 2
lowest for id 3: 1


Create a new paste based on this one


Comments: