3 Replies - 2509 Views - Last Post: 17 August 2010 - 03:55 PM Rate Topic: -----

#1 CTphpnwb  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 2486
  • View blog
  • Posts: 8,533
  • Joined: 08-August 08

Where the code tags are!

Posted 28 April 2010 - 05:01 PM

Code tags are used to keep your code's indenting and other formatting information. This makes your code easier to read than without it. See example below.
This code block is easier to read than the same code without it:
<?php
class cart {
	var $items;
	
	function add_item($x)  // $x is an array
	{
		$this->items[] = $x;
	}
	
	function remove_item($skew) // $skew is the sku number of item to be removed
	{
		for($i = 0; $i < count($this->items); $i++)
		{
			if($this->items[$i]['sku'] == $skew)
			{
				unset($this->items[$i]);
				$this->items = array_values($this->items);
			}
		}
	}
	
	function dislpay_items()
	{
		$total = 0;
		for($i = 0; $i < count($this->items); $i++)
		{
			echo "Item number: ".$i." sku: ".$this->items[$i]['sku']." Price: ".$this->items[$i]['price']." Qty: ".$this->items[$i]['qty']." subtotal: ".$this->items[$i]['price']*$this->items[$i]['qty']."<br>";
			$total += $this->items[$i]['price'] * $this->items[$i]['qty'];
		}
		echo "Total: ".$total."<br>";
	}
}

session_start();
//session_destroy();

if(isset($_SESSION['myclass']))
{
	$mycart = $_SESSION['myclass'];
	$mycart->remove_item(343);
} else
{
	$mycart = new cart;
	$mycart->add_item(array('sku'=>101, 'price'=>1.25 , 'qty'=>12));	
	$mycart->add_item(array('sku'=>343, 'price'=>99.95, 'qty'=>2));	
	$mycart->add_item(array('sku'=>233, 'price'=>4.99, 'qty'=>6));	
}	
$mycart->dislpay_items();

$_SESSION['myclass'] = $mycart;
?>

<?php
class cart {
var $items;

function add_item($x) // $x is an array
{
$this->items[] = $x;
}

function remove_item($skew) // $skew is the sku number of item to be removed
{
for($i = 0; $i < count($this->items); $i++)
{
if($this->items[$i]['sku'] == $skew)
{
unset($this->items[$i]);
$this->items = array_values($this->items);
}
}
}

function dislpay_items()
{
$total = 0;
for($i = 0; $i < count($this->items); $i++)
{
echo "Item number: ".$i." sku: ".$this->items[$i]['sku']." Price: ".$this->items[$i]['price']." Qty: ".$this->items[$i]['qty']." subtotal: ".$this->items[$i]['price']*$this->items[$i]['qty']."<br>";
$total += $this->items[$i]['price'] * $this->items[$i]['qty'];
}
echo "Total: ".$total."<br>";
}
}

session_start();
//session_destroy();

if(isset($_SESSION['myclass']))
{
$mycart = $_SESSION['myclass'];
$mycart->remove_item(343);
} else
{
$mycart = new cart;
$mycart->add_item(array('sku'=>101, 'price'=>1.25 , 'qty'=>12));
$mycart->add_item(array('sku'=>343, 'price'=>99.95, 'qty'=>2));
$mycart->add_item(array('sku'=>233, 'price'=>4.99, 'qty'=>6));
}
$mycart->dislpay_items();

$_SESSION['myclass'] = $mycart;
?>



If you want help you should do everything you can to make it easy for people who aren't paid to help you, to do that! That means clearly explaining your problem, your attempts to solve it, and posting the relevant portion of the code inside code blocks.

Following the rules makes it more likely that you will receive the help you need, so why not do it?

See image for code tag icon location and tags.

Attached image(s)

  • Attached Image

This post has been edited by CTphpnwb: 28 April 2010 - 05:02 PM


Is This A Good Question/Topic? 3
  • +

Replies To: Where the code tags are!

#2 karimi  Icon User is offline

  • Banned
  • member icon

Reputation: -9
  • View blog
  • Posts: 104
  • Joined: 29-May 09

Re: Where the code tags are!

Posted 20 May 2010 - 01:00 AM

ok
Was This Post Helpful? -2
  • +
  • -

#3 mattc  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 14
  • Joined: 22-September 09

Re: Where the code tags are!

Posted 17 August 2010 - 03:46 PM

True. Would be even better if there was a way selecting text with the mouse could understand BBcode and not copy the stupid line numbers.

And, Yes I do know there is button that allows me to open a button to copy it but sometimes Il only need 1 or 2 lines from any example.
Was This Post Helpful? 0
  • +
  • -

#4 AdamSpeight2008  Icon User is offline

  • MrCupOfT
  • member icon


Reputation: 1959
  • View blog
  • Posts: 8,700
  • Joined: 29-May 08

Re: Where the code tags are!

Posted 17 August 2010 - 03:55 PM

We're testing out an update (on the dev site), which has an improvement in regards to selecting code.


Syntax Highlighter that DIC uses. (Version 2.1.382)
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1