BigToach.com

PHP Snippets

get_world_pop

Information

(PHP Version >= 3.0.12)
Functions used in this snippet: date, strtotime, time, number_format.

Description

str get_world_pop( [int seconds[, bool english]] )

calling get_world_pop with no arguements will return a formatted string of the estimated current world population at that second. If you supply the seconds parameter it will supply the world population for the date as long as it is between the years of 2005 and 2048. If the english value is set to false the formatted string will have periods instead of commas seperating thousands and hundreds etc.

Snippet

<?php
function get_world_pop($seconds=NULL,$english=true){
    
$pops = array(
            
"2005" => array( "start" => 6451058790"added" => 74427813),
            
"2006" => array( "start" => 6525486603"added" => 74629207),
            
"2007" => array( "start" => 6600115810"added" => 74940532),
            
"2008" => array( "start" => 6675056342"added" => 75228043),
            
"2009" => array( "start" => 6750284385"added" => 75466071),
            
"2010" => array( "start" => 6825750456"added" => 75688866),
            
"2011" => array( "start" => 6901439322"added" => 75802963),
            
"2012" => array( "start" => 6977242285"added" => 75615963),
            
"2013" => array( "start" => 7052858248"added" => 75167390),
            
"2014" => array( "start" => 7128025638"added" => 74490498),
            
"2015" => array( "start" => 7202516136"added" => 73766792),
            
"2016" => array( "start" => 7276282928"added" => 73055605),
            
"2017" => array( "start" => 7349338533"added" => 72230253),
            
"2018" => array( "start" => 7421568786"added" => 71289623),
            
"2019" => array( "start" => 7492858409"added" => 70235773),
            
"2020" => array( "start" => 7563094182"added" => 69180831),
            
"2021" => array( "start" => 7632275013"added" => 68144353),
            
"2022" => array( "start" => 7700419366"added" => 67028250),
            
"2023" => array( "start" => 7767447616"added" => 65862519),
            
"2024" => array( "start" => 7833310135"added" => 64679285),
            
"2025" => array( "start" => 7897989420"added" => 63596858),
            
"2026" => array( "start" => 7961586278"added" => 62635490),
            
"2027" => array( "start" => 8024221768"added" => 61689308),
            
"2028" => array( "start" => 8085911076"added" => 60746079),
            
"2029" => array( "start" => 8146657155"added" => 59800227),
            
"2030" => array( "start" => 8206457382"added" => 58925303),
            
"2031" => array( "start" => 8265382685"added" => 58132001),
            
"2032" => array( "start" => 8323514686"added" => 57333600),
            
"2033" => array( "start" => 8380848286"added" => 56512857),
            
"2034" => array( "start" => 8437361143"added" => 55666984),
            
"2035" => array( "start" => 8493028127"added" => 54846652),
            
"2036" => array( "start" => 8547874779"added" => 54058633),
            
"2037" => array( "start" => 8601933412"added" => 53249683),
            
"2038" => array( "start" => 8655183095"added" => 52414904),
            
"2039" => array( "start" => 8707597999"added" => 51542658),
            
"2040" => array( "start" => 8759140657"added" => 50686755),
            
"2041" => array( "start" => 8809827412"added" => 49847392),
            
"2042" => array( "start" => 8859674804"added" => 48957732),
            
"2043" => array( "start" => 8908632536"added" => 48019825),
            
"2044" => array( "start" => 8956652361"added" => 47040969),
            
"2045" => array( "start" => 9003693330"added" => 46074635),
            
"2046" => array( "start" => 9049767965"added" => 45123225),
            
"2047" => array( "start" => 9094891190"added" => 44148176),
            
"2048" => array( "start" => 9139039366"added" => 43161841));
            
    
$yearly 31535999// seconds in a year usually
    
    
if($seconds !== NULL){
        
$year date('Y',$seconds);    
        
$thisyear $seconds strtotime('jan 1 ' $year ' 00:00');
    }else{
        
$year date('Y');    
        
$thisyear time() - strtotime('jan 1 ' $year ' 00:00');
    }
    
$sep $english ',' '.';
    return 
number_format(($pops[$year]['start'] + (($thisyear $yearly) * $pops[$year]['added'])),0,'.',$sep);
}
?>

Example

get_world_pop Can be used in the following way:

<?php
echo get_world_pop(); 
// returns the current world population formatted like 6,578,968,451

echo get_world_pop(strtotime('July 6 2010'));
// returns the world estimated world populating on july 6 2010

echo get_world_pop(NULL,false); 
// returns the current world population formatted like 6.578.968.451
?>

Added on Jul 5th at 1 am by Scott - 0 Comments


0 Responses to get_world_pop

Name:

Site or Mail:

Comment:

To try to reduce the ammount of spam, please enter the word GOOSE in the following form

Security Code: