PHP array functions indeed very powerful. Here’s couple tricks I usually used on my office projects when dealing with arrays.

Slurping Files and Trim each lines

slurping is reading the contents of file in a variables. It’s fast and efficient, but very resource hogging. Use it with careful

Instead of

$file = 'x.txt';
$lines = array();
$fp = fopen($file, 'r');
  if ($line = trim(fgets($fp, 1024)))
    $lines[] = $line;

Try to use this, its much clearer

$file = 'x.txt';
$lines = array_filter(array_map('trim', file($file)));

Unique Lines

Retrieve unique values from $array

$unique = array_unique($array);

Utilizing Arrays

Now how we can utilizing arrays, not just for storing data, we can use it for
doing so many boring things in programming and make it fun

Retrieveing Form Values

Using arrays, we can retrieve form values in just a couple of lines

$fields = array('username', 'password', 'confirmed_password', 'email');
foreach($fields as $field)
  $$field = isset($_POST[$field]) 
    ? trim(get_magic_quotes_gpc() ? stripslashes($_POST[$field]) : $_POST[$field])
    : '';

// now we can use it
if ($password != $confirmed_password)
  die('Invalid password!');

Building SQL statements with arrays

We usually concat string to build SQL statement, don’t, concat is dirty. Use array,
it much cleaner

$q = get_magic_quotes_gpc() ? stripslashes(@$_GET['q']) : @$_GET['q'];
$cat = get_magic_quotes_gpc() ? stripslashes(@$_GET['cat']) : @$_GET['cat'];

// add conditions
$where = array();
if ($q) $where[] = sprintf("text LIKE '%%%s%%'", addcslashes(mysql_real_escape_string($q), '%_?*'));
if ($cat) $where[] = sprintf("cat = '%s'", mysql_real_escape_string($cat));

// now build query string
$wherestr = empty($where) ? '' : ' where ' . implode(' and ', $where);
$sql = "select * from table $wherestr";
echo $sql;

That’s for now, you can explore another PHP array capabilities. Have fun!