Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

How to manipulate an array


djmonkey1

Recommended Posts

So say we have an array like so:

 

$TotalsArray = array();
for ($i=0; $i<sizeof($order->totals); $i++) {
	$TotalsArray[] = array("Name" => $order->totals[$i]['title'], "Price" => number_format($order->totals[$i]['value'], 2, '.', ''), "Class" => $order->totals[$i]['class'], "TotalID" => $order->totals[$i]['orders_total_id']);
	$TotalsArray[] = array("Name" => "		  ", "Price" => "", "Class" => "ot_custom", "TotalID" => "0");
}

array_pop($TotalsArray);
foreach($TotalsArray as $TotalIndex => $TotalDetails)
{
	$TotalStyle = "smallText";
	if($TotalDetails["Class"] == "ot_total")
	{
		echo '   bark' . "\n";
	}
	elseif($TotalDetails["Class"] == "ot_subtotal") 
	{
		echo '	like' . "\n";
	}
	elseif($TotalDetails["Class"] == "ot_tax")
	{
		echo '	a' . "\n";
	}
		else
	{
		echo '	dog' . "\n";
	}
}

 

Is it possible to manipulate the array in such a way that if the class "ot_tax" is not found, it could generate a command that would echo "my" and put it in the sentence whrere "a" would go (obviously what those conditions actually execute when met is important but I've deleted them for brevity)?

 

Or, maybe better yet (although this may pigeonhole us) run a check before the foreach loop that determines whether an entry with the class "ot_tax" exists, and if not then create one, and once that is done run the loop?

Do, or do not. There is no try.

 

Order Editor 5.0.6 "Ultra Violet" is now available!

For support or to post comments, suggestions, etc, please visit the Order Editor support thread.

Link to comment
Share on other sites

Never mind- I've done the check that I wanted to do in a totallly different way and in a completely different place in the file.

Do, or do not. There is no try.

 

Order Editor 5.0.6 "Ultra Violet" is now available!

For support or to post comments, suggestions, etc, please visit the Order Editor support thread.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...