Skip to content

Instantly share code, notes, and snippets.

@valdiney
Last active August 29, 2015 14:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save valdiney/699ae6e4c0bcb860539f to your computer and use it in GitHub Desktop.
Save valdiney/699ae6e4c0bcb860539f to your computer and use it in GitHub Desktop.
This class is used to work with data structure know as list
<?php
/**
* This class is used to work with data structure know as list
* @author Valdiney França <valdiney.2@hotmail.com>
* @var $list -> Array
*/
namespace structureClass;
class MyList
{
protected $list;
#This method set a list into the class
public function setList($list = array())
{
$this->list = $list;
}
#This method return the list used by the class
public function getList()
{
return $this->list;
}
#This method is used to set values into the last position of the list
public function pushInList($value = null)
{
array_push($this->list, $value);
}
#This method is used to set values in a specific position of the list
public function pushingInPosition($position = null, $value = null)
{
if (!array_key_exists($position, $this->list))
{
$this->list[$position] = $value;
}
return false;
}
#This method is used to get a specific position of the list
public function getListInPosition($position = null)
{
if (array_key_exists($position, $this->list))
{
return $this->list[$position];
}
return false;
}
#This method is used to delete a specific position of the list
public function deleteListInPosition($position)
{
if (array_key_exists($position, $this->list))
{
unset($this->list[$position]);
}
return false;
}
#This method clear every values into the list
public function clearList()
{
for ($i = 0; $i < $this->listSize(); $i++)
{
unset($this->list[$i]);
}
}
#This method return a regenerate list
public function getListRegenerate()
{
return array_merge($this->list);
}
#This method verify if specific value exist inside the list
public function valueResearch($value)
{
if (in_array($value, $this->list))
{
return true;
}
return false;
}
#This method return the size of the list
public function listSize()
{
return count($this->list);
}
}
/* End of file MyList.php */
/* Location: structureClass */
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment