eXorithm – Execute Algorithm: View / Run Algorithm freebase_populations

function freebase_populations ($countries
{
  $query = array'type'=>'/location/country'
                 'name'=>null, 
                 'query:name|='=>$countries
                 'iso3166_1_alpha2!='=>''
                 '/location/statistical_region/population'=> arrayarray
                   'limit'=>1,
                   'number'=>null,
                   'year'=>null,
                   'sort'=>'-year'
                 )) );
  
  $results = freebase_query$query);
  
  $return = array();
  foreach ($results as $result) {
    if (isset$result'/location/statistical_region/population'][0]['number'])) {
      $return$result'name']] = $result'/location/statistical_region/population'][0]['number'];
    }
  }
  return $return

eXorithm – Execute Algorithm: View / Run Algorithm image_create_alpha

function image_create_alpha ($width$height

{

  // Create a normal image and apply required settings

  $img = imagecreatetruecolor$width$height);

  imagealphablending$img, false);

  imagesavealpha$img, true);

  

  // Apply the transparent background

  $trans = imagecolorallocatealpha$img, 0, 0, 0, 127);

  for ($x = 0; $x < $width$x++)

  {

    for ($y = 0; $y < $height$y++)

    {

      imagesetpixel$img$x$y$trans);

    }

  }

  

  return $img

eXorithm – Execute Algorithm: View / Run Algorithm multicolumn

function multicolumn ($items$type$rows$columns$table_attributes$td_attributes$empty_attributes

{

  $return = ''

  $count = count$items);

  

  // compute number of columns and rows

  if (($rows=='*') && ($columns=='*')) {

    $rows = roundsqrt$count));

    $columns = ceil$count$rows);

  } else {

    if ($rows=='*'

      $rows = ceil$count$columns);

    else if ($columns=='*'

      $columns = ceil$count$rows);

  }

  

  

  if ($count>0) {

    $return .= "<table $table_attributes>"

    $column = 0;

    $row = 0;

    $total = $rows * $columns

    for ($i=0;$i$total$i++) {

      if$column == 0)

        $return .= '<tr>'

      

      if ($type=='horizontal'

        $spot = $i

      else

        $spot = $row$column$rows

     

      if ($spot$count

        $return .= "<td $td_attributes>$items[$spot]</td>"

      else

        $return .= "<td $empty_attributes></td>"

  

      $column++;

   

      if ($column==$columns) {

        $return .= '</tr>'

        $column = 0;

        $row++;

      }

    }

    

    $return .= '</table>'

  }

  

  return $return

eXorithm – Execute Algorithm: View / Run Algorithm coin_change

function coin_change ($amount, $coins

{

  $change = array();

  rsort$coins);

  for$i=0; $icount$coins); $i++) {

    $change$coins$i]] = floor$amount$coins$i]);

    $amount = $amount % $coins$i];

  }

  return $change

} 

eXorithm – Execute Algorithm: View / Run Algorithm bytes2human

function bytes2human ($bytes$precision

{

  switch (true) {

    case $bytes < 1024:

      return number_format$bytes).($bytes==1 ? " Byte" : " Bytes");

    case round$bytes / 1024) < 1024:

      return number_format$bytes / 1024, $precision)." KB"

    case round$bytes / 1024 / 1024, 2) < 1024:

      return number_format$bytes / 1024 / 1024, $precision)." MB"

    case round$bytes / 1024 / 1024 / 1024, 2) < 1024:

      return number_format$bytes / 1024 / 1024 / 1024, $precision)." GB"

    default

      return number_format$bytes / 1024 / 1024 / 1024 / 1024, $precision)." TB"

  }

Sum List

<?php

/**
 * sum_list
 *
 * Sum up the numbers in an array.
 *
 * @version 0.1
 * @author Contributors at eXorithm
 * @link https://www.exorithm.com/algorithm/view/sum_list Listing at eXorithm
 * @link https://www.exorithm.com/algorithm/history/sum_list History at eXorithm
 * @license https://www.exorithm.com/home/show/license
 *
 * @param array $numbers 
 * @return number
 */
function sum_list($numbers=array(0=>'2',1=>'4',2=>'12',3=>'1'))
{
	return array_sum($numbers);
}

?>