CODEFETCH™
            Examples
Searched for 1 expression(s): array  
PHP API
array search codefetch
Create an array
array_change_key_case search codefetch
Returns an array with all string keys lowercased or uppercased
array_chunk search codefetch
Split an array into chunks
array_combine search codefetch
Creates an array by using one array for keys and another for its values
array_count_values search codefetch
Counts all the values of an array
Most relevant API matches shown. View All.
Source code below from:
Beginning PHP and MySQL 5: From Novice to Professional, Second Edition (Beginning: from Novice to Professional)
By W. Jason Gilmore
Published 23 January, 2006
Average rating

      Powells     Alibris

1590595521/ch12/getarray.php (10 lines)
3 $date = new Date(); 
4 $date->setDMY(29,4,2005); 
5 $dcs = $date->getArray();
6 echo "The month: ".$dcs['month']."<br />"; 
7 echo "The day: ".$dcs['day']."<br />"; 

1590595521/ch22/sqlite_array_query.php (8 lines)
1 <?php 
2    $sqldb = sqlite_open("mydatabase.db"); 
3    $rows = sqlite_array_query($sqldb, "SELECT empid, name FROM employee");
4    foreach ($rows AS $row) { 
5       echo $row["name"]." (Employee ID: ".$row["empid"].")<br />"; 

1590595521/ch22/sqlite_fetch_array-2.php (8 lines)
2    $sqldb = sqlite_open("mydatabase.db"); 
3    $results = sqlite_query($sqldb, "SELECT * FROM employee"); 
4    while (list($empid, $name) = sqlite_fetch_array($results)) {
5           echo "Name: $name (Employee ID: $empid)<br />"; 
6    } 

1590595521/ch22/sqlite_fetch_array.php (8 lines)
2    $sqldb = sqlite_open("mydatabase.db"); 
3    $results = sqlite_query($sqldb, "SELECT * FROM employee"); 
4    while ($row = sqlite_fetch_array($results,SQLITE_BOTH)) {
5           echo "Name: $row[1] (Employee ID: ".$row['empid'].")<br />"; 
6    } 

1590595521/ch29/mysql_fetch_array-2.php (8 lines)
1 $query = "SELECT productid, name FROM product ORDER BY name"; 
2 $result = mysql_query($query); 
3 while ($row = mysql_fetch_array($result, MYSQL_NUM))
4 { 
5     $name = $row[1]; 
Source code below from:
Foundation PHP for Dreamweaver 8
By David Powers
Published 19 December, 2005
Average rating

      Powells     Alibris

FdnPHPforDW8/examples/ch11/date_converter.php (65 lines)
1 <?php 
2 $months = array('Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec');
3 $now = getdate(); 
4 if ($_POST) { 

FdnPHPforDW8/site_check/ch06/contact_03.php (64 lines)
1 <?php 
2 if (array_key_exists('ewComments', $_POST)) {
3   // mail processing script 
4   // initialize variables 

FdnPHPforDW8/site_check/ch06/contact_04.php (76 lines)
1 <?php 
2 if (array_key_exists('ewComments', $_POST)) {
3   // mail processing script 
4   // remove escape characters from POST array
5 if (get_magic_quotes_gpc()) { 
6   function stripslashes_deep($value) { 
7     $value = is_array($value) ? array_map('stripslashes_deep', $value) : stripslashes($value);
8     return $value; 
9     } 
10   $_POST = array_map('stripslashes_deep', $_POST);
11   } 
12   // initialize variables 

FdnPHPforDW8/site_check/ch06/contact_05.php (129 lines)
1 <?php 
2 if (array_key_exists('ewComments', $_POST)) {
3   // mail processing script 
4   // remove escape characters from POST array
5 if (get_magic_quotes_gpc()) { 
6   function stripslashes_deep($value) { 
7     $value = is_array($value) ? array_map('stripslashes_deep', $value) : stripslashes($value);
8     return $value; 
9     } 
10   $_POST = array_map('stripslashes_deep', $_POST);
11   } 
12   // validate the input, beginning with name 

FdnPHPforDW8/site_check/ch06/contact_06.php (129 lines)
1 <?php 
2 if (array_key_exists('ewComments', $_POST)) {
3   // mail processing script 
4   // remove escape characters from POST array
5 if (get_magic_quotes_gpc()) { 
6   function stripslashes_deep($value) { 
7     $value = is_array($value) ? array_map('stripslashes_deep', $value) : stripslashes($value);
8     return $value; 
9     } 
10   $_POST = array_map('stripslashes_deep', $_POST);
11   } 
12   // validate the input, beginning with name 
Source code below from:
PHP Hacks : Tips & Tools For Creating Dynamic Websites (Hacks)
By Jack Herrington
Published 12 December, 2005
Average rating

      Powells     Alibris

phphacks/amazon/index.php (121 lines)
34   global $amazon; 
35  
36   $out = array();
37   $products = $amazon->searchKeyword($keyword, "books", 1); 
38   if( $products != null ) 
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
49 50 if ( strlen( $product['name'] ) > 0 ) 51 $out[ $product['asin'] ] = array( 52 'url' => $product['url'], 53 'imagesmall' => $product['imagesmall'],
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
70 $listb = find_books( $termb ); 71 72 $overlaps = array(); 73 $onlya = array(); 74 $onlyb = array(); 75 76 foreach( array_keys( $lista ) as $asin ) 77 { 78 if ( array_key_exists( $asin, $listb ) ) 79 $overlaps[ $asin ] = $lista[$asin]; 80 else
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
83 foreach( array_keys( $listb ) as $asin ) 84 { 85 if ( !array_key_exists( $asin, $lista ) ) 86 $onlyb[ $asin ] = $listb[$asin]; 87 }
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
108 109 <table width="100%" cellspacing="0" cellpadding="0" border="0"> 110 <tr><td><?php list_products( array_values( $overlaps ) ); ?></td></tr> 111 </table> 112 113 <table width="100%" cellspacing="0" cellpadding="0" border="0"> 114 <tr><td valign="top" width="50%"><?php list_products( array_values( $onlya ) ); ?></td> 115 <td valign="top" width="50%"><?php list_products( array_values( $onlyb ) ); ?></td></tr> 116 </table> 117

phphacks/awss/index.php (95 lines)
1 <?php $states = array(
2   array( "Alabama",4447100,1963711,52419.02,1675.01,50744,87.6,38.7 ),
3   array( "Alaska",626932,260978,663267.26,91316,571951.26,1.1,0.5 ),
4   array( "Arizona",5130632,2189189,113998.3,363.73,113634.57,45.2,19.3 ),
5   array( "Arkansas",2673400,1173043,53178.62,1110.45,52068.17,51.3,22.5 ),
6   array( "California",33871648,12214549,163695.57,7736.23,155959.34,217.2,78.3 ),
7   array( "Colorado",4301261,1808037,104093.57,376.04,103717.53,41.5,17.4 ),
8   array( "Connecticut",3405565,1385975,5543.33,698.53,4844.8,702.9,286.1 ),
9   array( "Delaware",783600,343072,2489.27,535.71,1953.56,401.1,175.6 ),
10   array( "District of Columbia",572059,274845,68.34,6.94,61.4,9316.4,4476.1 ),
11   array( "Florida",15982378,7302947,65754.59,11827.77,53926.82,296.4,135.4 ),
12   array( "Georgia",8186453,3281737,59424.77,1518.63,57906.14,141.4,56.7 ), 
13   array( "Hawaii",1211537,460542,10930.98,4508.36,6422.62,188.6,71.7 ), 

phphacks/breadcrumbs/showpage.php (46 lines)
4   $id = "home"; 
5  
6 $pages = array(
7   home => array( id=>"home", parent=>"", title=>"Home", url=>"showpage.php?id=home" ),
8   users => array( id=>"users", parent=>"home", title=>"Users", url=>"showpage.php?id=users" ),
9   jack => array( id=>"jack", parent=>"users", title=>"Jack", url=>"showpage.php?id=jack" )
10   ); 
11  
12 function breadcrumbs( $id, $pages ) 
13 { 
14   $bcl = array();
15   $pageid = $id; 
16   while( strlen( $pageid ) > 0 ) 

phphacks/cal/cal.php (175 lines)
78   $lastyear = $year; 
79   if ( $lastmonth < 0 ) { $lastmonth = 11; $lastyear -= 1; } 
80   return array( $lastmonth, $lastyear );
81 } 
82  
83 function get_next_month( $month, $year ) 
84 { 
85   $nextmonth = $month + 1; 
86   $nextyear = $year; 
87   if ( $nextmonth > 11 ) { $nextmonth = 0; $nextyear += 1; } 
88   return array( $nextmonth, $nextyear );
89 } 
90  
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
100 $dim = cal_days_in_month( CAL_GREGORIAN, $month + 1, $year ); 101 102 $days = array( ); 103 104 for( $d = 0; $d < $day; $d++ )
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
128 setCalendarText( &$days, $month + 1, 10, $year, "Meet<br/>Sue" ); 129 130 $months = array( 131 "January", "February", "March", "April", 132 "May", "June", "July", "August", 133 "September", "October", "November", "December" ); 134 $day_names = array( "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" ); 135 ?> 136 <div style="width:600px;">

phphacks/checklinks/checklinks.php (34 lines)
11   print( $doc ); 
12  
13   $badlinks = array();
14   foreach( $found[1] as $link ) 
15   { 
Source code below from:
PHP Phrasebook (Developer's Library)
By Christian Wenz
Published 26 September, 2005
Average rating

      Powells     Alibris

ch02-arrays/array_filter.php (17 lines)
8   } 
9  
10   $values = array(
11     'valid@email.tld', 
12     'invalid@email', 
13     'also@i.nvalid', 
14     'also@val.id' 
15   ); 
16   echo implode(', ', array_filter($values, 'checkMail'));
17 ?> 

ch02-arrays/array_map.php (9 lines)
4   } 
5    
6   $a = array('harmless', '<bad>', '>>click here!<<');
7   $a = array_map('sanitize', $a);
8   echo implode(' ', $a); 
9 ?> 

ch02-arrays/array_map_recursive.php (19 lines)
1 <?php 
2   function sanitize_recursive($s) { 
3     if (is_array($s)) {
4       return(array_map('sanitize_recursive', $s));
5     } else { 
6       return htmlspecialchars($s); 
7     } 
8   } 
9    
10   $a = array(
11     'harmless' =>  
12       array('no', 'problem'), 
13     'harmful' =>  
14       array('<bad>', '--> <worse> <<-')
15   );  
16  

ch02-arrays/array_rand.php (7 lines)
4   } 
5  
6   echo implode(' ', array_rand($numbers, 6));
7 ?> 

ch02-arrays/array_walk.php (10 lines)
6    
7   $i = 1; 
8   $a = array('one', 'two', 'three', 'four');
9   $a = array_walk($a, 'printElement', $i);
10 ?> 
Source code below from:
Pro PHP Security (Pro)
By Chris Snyder and Michael Southwell
Published 29 August, 2005
Average rating

      Powells     Alibris

CHAPTER03/resetPermissions.php (95 lines)
3  
4 // (sample) presets 
5 $presets = array( 'production-www'=>'root:www-0750',
6                   'shared-dev'=>':www-2770', 
7                   'all-mine'=>'-0700' 
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
38 $location = $argv[1]; 39 $preset = $argv[2]; 40 if ( !array_key_exists( $preset, $presets ) ) { 41 print 'Invalid preset.\n\n'; 42 exit( $usage );

CHAPTER06/integrity.php (183 lines)
19         // get all file statistics, see http://php.net/stat 
20         // slice off numeric indexes, leaving associative only 
21         $this->stats = array_slice( stat( $this->path ), 13 );
22  
23         // ignore atime (changes with every read), rdev, and blksize (irrelevant) 
24         unset( $this->stats['atime'] ); 
25         unset( $this->stats['rdev'] ); 
26         unset( $this->stats['blksize'] ); 
27  
28         // compute md5 hash of serialized stats array
29         $statsHash = md5( serialize( $this->stats ) ); 
30  
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
43 44 // initial values 45 $found = array(); 46 $known = FALSE; 47
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
59 integrity of the specified files. 60 If not, a new index is generated and written to std-out. 61 The index is a serialized PHP array, with one entry per file.\r\n\r\n" ); 62 } 63
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
91 $file->load( $path . '/' . $entry ); 92 93 // if readable, assign to $found array 94 if ( !empty( $file->combinedHash ) ) { 95 $found[ $file->path ] = $file;

CHAPTER06/openSSL.php (47 lines)
4     private $certificate; 
5     private $privatekey; 
6     private $dn = array();
7     private $x509 = array();
8     private $sigheader = "\n-----BEGIN openSSL.php SIGNATURE-----\n"; 
9     private $sigfooter = "-----END openSSL.php SIGNATURE-----\n"; 
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
21 22 // generate the pem-encoded private key 23 $config = array( 'digest_alg'=>'sha1', 24 'private_key_bits'=>1024, 25 'encrypt_key'=>TRUE,

CHAPTER06/openSSLDemo.php (61 lines)
9  
10   // a "Distinguished Name" is required for the public key 
11   $distinguishedName = array(
12     "countryName" => "US", 
13     "stateOrProvinceName" => "New York", 

CHAPTER06/passwordHashingDemo.php (95 lines)
21 // check that it meets our password criteria; 
22 // provide a message (and regenerate the login form) if it doesn't 
23 $passwordProblem = array();
24 if ( strlen( $userPassword ) < 8 ) { 
25   $passwordProblem[] = 'It must be at least eight characters long.'; 
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
78 if ( !$result ) exit( "$userName wasn't found in the database!" ); 79 80 $row = mysql_fetch_array( $result ); 81 82 $storedPassword = $row['password'];
Source code below from:
Spring Into PHP 5 (Spring Into)
By Steven Holzner
Published 12 April, 2005
Average rating

      Powells     Alibris

ch03/phparray.php (26 lines)
2         <HEAD> 
3             <TITLE> 
4                 Modifying an array
5             </TITLE> 
6         </HEAD> 
7  
8         <BODY> 
9             <H1> 
10                 Modifying an array
11             </H1> 
12  

ch03/phparrayops.php (35 lines)
2         <HEAD> 
3             <TITLE> 
4                 Using array operators
5             </TITLE> 
6         </HEAD> 
7  
8         <BODY> 
9             <H1> 
10                 Using array operators
11             </H1> 
12             <?php 

ch06/phptextarray.php (22 lines)
2     <HEAD> 
3         <TITLE> 
4             Using Text Field Arrays
5         </TITLE> 
6     </HEAD> 
7     <BODY> 
8         <CENTER> 
9             <H1>Retrieving Data From Text Field Arrays</H1>
10             Your name is 
11             <?php  

ch02/phpforeach.php (19 lines)
11         </H1> 
12             <?php 
13                 $arr = array("apples", "oranges", "bananas");
14                 foreach ($arr as $value) { 
15                    echo "Current fruit: $value<BR>"; 

ch03/phpextract.php (25 lines)
2         <HEAD> 
3             <TITLE> 
4                 Extracting variables from an array
5             </TITLE> 
6         </HEAD> 
7  
8         <BODY> 
9             <H1> 
10                 Extracting variables from an array
11             </H1> 
12  
Source code below from:
Foundation PHP 5 for Flash (Foundation)
By David Powers
Published 01 March, 2005
Average rating

      Powells     Alibris

php files/appA/arrays.php (27 lines)
3 <head> 
4 <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> 
5 <title>Changing array values</title>
6 </head> 
7  
8 <body> 
9 <?php 
10 $titles = array('PHP 5 for Flash', 'ActionScript for Flash MX 2004');
11 echo '<pre>'; 
12 echo '<h2>Using a foreach loop</h2>'; 

php files/ch05/array_slice1.php (16 lines)
1 <?php 
2 $characters = array('Bilbo', 'Frodo', 'Sam', 'Gandalf', 'Arathorn');
3 // start index is 3 - in other words the fourth item 
4 // no end index, so it extracts to the end of the array
5 $goodguys = array_slice($characters, 3);
6 // start index is negative, so it counts from the end of the array
7 // and extracts from that point 
8 // again no end index, so extracts to the end of the array
9 $goodguys2 = array_slice($characters, -2);
10 // display both results and the original array
11 echo '<pre>'; 
12 print_r($goodguys); 

php files/ch05/array_slice2.php (11 lines)
1 <?php 
2 $characters = array('Bilbo', 'Frodo', 'Sam', 'Gandalf', 'Arathorn');
3 $theOne = array_slice($characters, 1, -3);
4 $thePositiveOne = array_slice($characters, 1, 1);
5 // display both results and the original array
6 echo '<pre>'; 
7 print_r($theOne); 

php files/ch05/array_splice1.php (8 lines)
1 <?php 
2 $characters = array('Bilbo', 'Frodo', 'Sam', 'Gandalf', 'Arathorn');
3 $goodguys = array_splice($characters, 3);
4 echo '<pre>'; 
5 print_r($goodguys); 

php files/ch05/array_splice2.php (45 lines)
3 <head> 
4 <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> 
5 <title>Demonstration of array_splice()</title>
6 <style type="text/css"> 
7 body {font: 85% Arial, Helvetica, sans-serif;} 
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
14 15 <body> 16 <h1>Working with array_splice() 2</h1> 17 <h2>Original array</h2> 18 <?php 19 $characters = array('Bilbo', 'Frodo', 'Sam', 'Gandalf', 'Arathorn'); 20 echo '<pre>'; 21 print_r($characters); 22 echo '</pre>'; 23 $whiteWizard = array_splice($characters, 3, 1); 24 ?> 25 <h2>After $whiteWizard = array_splice($characters, 3, 1);</h2> 26 <?php 27 echo '<pre>';
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
29 echo '</pre>'; 30 ?> 31 <h2>$whiteWizard now contains a new array</h2> 32 <?php 33 echo '<pre>'; 34 print_r($whiteWizard); 35 echo '</pre>'; 36 array_splice($characters, 3, 0, $whiteWizard); 37 ?> 38 <h2>$whiteWizard reintegrated using array_splice($characters, 3, 0, $whiteWizard);</h2> 39 <?php 40 echo '<pre>';
Source code below from:
Beginning PHP5, Apache, and MySQL Web Development (Programmer to Programmer)
By Elizabeth Naramore, Jason Gerner, Yann Le Scouarnec, Jeremy Stolz, and Michael K. Glass
Published 04 February, 2005
Average rating

      Powells     Alibris

Appedix A Example Files/ch04ex01.php (418 lines)
258 <?php 
259       //retrieve a jobs list from the database 
260       $jobs_array[0]["title"] = "Marketing Manager";
261       $jobs_array[0]["salary"] = 40000;
262       $jobs_array[0]["years_experience_required"] = 2;
263       $jobs_array[0]["degree_required"] = "Doctorate";
264       $jobs_array[0]["commission"] = "No";
265       $jobs_array[0]["job_id"] = "A";
266  
267       $jobs_array[1]["title"] = "Sales Manager";
268       $jobs_array[1]["salary"] = 30000;
269       $jobs_array[1]["years_experience_required"] = 1;
270       $jobs_array[1]["degree_required"] = "Masters";
271       $jobs_array[1]["commission"] = "Yes";
272       $jobs_array[1]["job_id"] = "B"; 
273  

Appedix A Example Files/ch07ex01.php (86 lines)
14  
15    //set the default directory 
16    $default_dir = array(realpath("/Inetpub/wwwroot/beginning_php5/appendix_a/"));
17  
18    //create an array to hold any matches
19    $matching_folder_file_names = array();
20  
21   while (count($default_dir) > 0) { 
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
26 $real_path_name = realpath($startingdir.'/'.$file); 27 if (is_dir($real_path_name)) { 28 if (!in_array($real_path_name, $matching_folder_file_names) && !in_array($real_path_name, $default_dir)) { 29 $default_dir[] = $real_path_name; 30 if ($folder_to_find == $file) {
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
42 } 43 44 $dir_list = array_unique($dir_list); 45 sort($dir_list); 46

chapter 02/moviesite-rev10.php (81 lines)
16 <?php include "header.php"; ?> 
17 <?php 
18 $favmovies = array("Life of Brian",
19                    "Stripes", 
20                    "Office Space", 

chapter 02/moviesite-rev11.php (66 lines)
16 <?php include "header.php"; ?> 
17 <?php 
18 $favmovies = array("Life of Brian",
19                    "Stripes", 
20                    "Office Space", 

chapter 03/select-rev01.php (24 lines)
14   or die(mysql_error()); 
15  
16 while ($row = mysql_fetch_array($results)) {
17   extract($row); 
18   echo $movie_name; 
Source code below from:
PHP 5 Objects, Patterns, and Practice
By Matt Zandstra
Published 21 December, 2004
Average rating

      Powells     Alibris

final-code/03/listing03.16.php (29 lines)
3  
4 class ShopProductWriter { 
5     private $products = array();
6  
7     public function addProduct( ShopProduct $shopProduct ) { 

final-code/04/listing04.05.php (52 lines)
3  
4 abstract class ShopProductWriter { 
5     protected $products = array();
6  
7     public function addProduct( ShopProduct $shopProduct ) { 

final-code/04/listing04.06.php (21 lines)
3  
4 abstract class ShopProductWriter { 
5     protected $products = array();
6  
7     public function addProduct( ShopProduct $shopProduct ) { 

final-code/04/listing04.08.05.php (60 lines)
26     private $dsn; 
27     private $db_obj; 
28     private $fields = array( "name", "age" );
29  
30     function __construct( $dsn ) { 
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
40 $this->connect(); 41 } 42 $row = array(); 43 foreach( $this->fields as $fieldname ) { 44 $method = "get{$fieldname}";

final-code/04/listing04.09.php (69 lines)
28     private $dsn; 
29     private $db_obj; 
30     private $fields = array( "name", "age" );
31  
32     function __construct( $dsn ) { 
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
45 $this->connect(); 46 } 47 $row = array(); 48 foreach( $this->fields as $fieldname ) { 49 $method = "get{$fieldname}";
Source code below from:
Professional PHP5 (Programmer to Programmer)
By Edward Lecky-Thompson, Heow Eide-Goodman, Steven D. Nowicki, and Alec Cove
Published 26 November, 2004
Average rating

      Powells     Alibris

ProPHP5CodeSeparations/ch01/class.Customer.php (23 lines)
11       //We're hard coding these values here, but in a real application 
12       //these values would come from a database      
13       $data = array();
14       $data['customerNumber'] = 1000000; 
15       $data['name'] = 'Jane Johnson'; 

ProPHP5CodeSeparations/ch01/class.Widget.php (75 lines)
29     } 
30          
31     $data = pg_fetch_array($rs);
32     $this->id = $widgetID; 
33     $this->name = $data['name']; 

ProPHP5CodeSeparations/ch02/sampleCode.php (152 lines)
33        $this->last = $last; 
34        $this->first = $first; 
35        $this->instruments = array();
36        $this->musicianType = "guitarist"; 
37     } 
38    
39     public function getName() { 
40       return $this->first . " " . $this->last; 
41     } 
42      
43     public function addInstrument(Instrument $instrument) { 
44        array_push($this->instruments, $instrument);
45     } 
46      
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
84 function __construct($bandName) { 85 $this->bandName = $bandName; 86 $this->musicians = array(); 87 $this->bandGenre = "rock"; 88 }
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
97 98 public function addMusician(Musician $musician){ 99 array_push($this->musicians, $musician); 100 $musician->assignToBand($this); 101 }

ProPHP5CodeSeparations/ch03/class.DataManager.php (187 lines)
70     
71     if(pg_num_rows($res)) { 
72       $objs = array();
73       while($rec = pg_fetch_assoc($res)) { 
74         $objs[] = new Address($rec['addressid']); 
75       } 
76       return $objs; 
77     } else { 
78       return array();
79     } 
80   } 
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
91 92 if(pg_num_rows($res)) { 93 $objs = array(); 94 while($rec = pg_fetch_assoc($res)) { 95 $objs[] = new EmailAddress($rec['emailid']); 96 } 97 return $objs; 98 } else { 99 return array(); 100 } 101 }
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
111 112 if(pg_num_rows($res)) { 113 $objs = array(); 114 while($rec = pg_fetch_assoc($res)) { 115 $objs[] = new PhoneNumber($rec['phoneid']); 116 } 117 return $objs; 118 } else { 119 return array(); 120 } 121 }
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
147 148 if(pgsql_num_rows($res)) { 149 $objs = array(); 150 while($row = pgsql_fetch_assoc($res)) { 151 $objs[] = new Individual($row['individualid']); 152 } 153 return $objs; 154 } else { 155 return array(); 156 } 157 }
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
167 168 if(pgsql_num_rows($res)) { 169 $objs = array(); 170 while($row = pgsql_fetch_assoc($res)) { 171 if($row['type'] == 'I') {
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
179 return $objs; 180 } else { 181 return array(); 182 } 183 }

ProPHP5CodeSeparations/ch03/class.PropertyObject.php (65 lines)
4   abstract class PropertyObject implements Validator { 
5     
6     protected $propertyTable = array();     //stores name/value pairs
7                                             //that hook properties to 
8                                             //database field names 
9                                             
10     protected $changedProperties = array(); //List of properties that
11                                             //have been modified 
12     
13     protected $data;                        //Actual data from 
14                                             //the database 
15                                             
16     protected $errors = array();            //Any validation errors
17                                             //that might have occurred 
18                                            
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
23 24 function __get($propertyName) { 25 if(!array_key_exists($propertyName, $this->propertyTable)) 26 throw new Exception("Invalid property \"$propertyName\"!"); 27 28 if(method_exists($this, 'get' . $propertyName)) { 29 return call_user_func(array($this, 'get' . $propertyName)); 30 } else { 31 return $this->data[$this->propertyTable[$propertyName]];
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
34 35 function __set($propertyName, $value) { 36 if(!array_key_exists($propertyName, $this->propertyTable)) 37 throw new Exception("Invalid property \"$propertyName\"!"); 38 39 if(method_exists($this, 'set' . $propertyName)) { 40 return call_user_func( 41 array($this, 'set' . $propertyName), 42 $value 43 );
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
45 46 //If the value of the property really has changed 47 //and it's not already in the changedProperties array, 48 //add it. 49 if($this->propertyTable[$propertyName] != $value && 50 !in_array($propertyName, $this->changedProperties)) { 51 $this->changedProperties[] = $propertyName; 52 }
Source code below from:
PHP 5 Power Programming (Bruce Perens Open Source)
By Andi Gutmans, Stig Bakken, and Derick Rethans
Published 27 October, 2004
Average rating

      Powells     Alibris

06/examples/peardb_error1.php (19 lines)
8 $dbh->query("CREATE UNIQUE INDEX mypets_idx ON mypets (name, species)"); 
9  
10 $data = array('Bill', 'Mule');
11  
12 for ($i = 0; $i < 2; $i++) { 

06/examples/peardb_prepexec1.php (21 lines)
3 require_once 'DB.php'; 
4  
5 $changes = array(
6     array(154351, "Trondheim", "NOR"),
7     array(521886, "Oslo", "NOR"),
8     array(112405, "Stavanger", "NOR"),
9     array(237430, "Bergen", "NOR"),
10     array(103313, "BÊrum", "NOR"),
11 ); 
12 PEAR::setErrorHandling(PEAR_ERROR_DIE, "%s<br />\n"); 

06/peardb_error1.php (19 lines)
8 $dbh->query("CREATE UNIQUE INDEX mypets_idx ON mypets (name, species)"); 
9  
10 $data = array('Bill', 'Mule');
11  
12 for ($i = 0; $i < 2; $i++) { 

06/peardb_prepexec1.php (21 lines)
3 require_once 'DB.php'; 
4  
5 $changes = array(
6     array(154351, "Trondheim", "NOR"),
7     array(521886, "Oslo", "NOR"),
8     array(112405, "Stavanger", "NOR"),
9     array(237430, "Bergen", "NOR"),
10     array(103313, "BÊrum", "NOR"),
11 ); 
12 PEAR::setErrorHandling(PEAR_ERROR_DIE, "%s<br />\n"); 

appendix_phpdoc/examples/elements/abstract.php (49 lines)
32 * Example inherited class 
33 *  
34 * Add two arrays
35 * @package Examples 
36 */ 
37 class SumArray extends Sum {
38  
39     /** 
40     * Add two arrays
41     * 
42     * @param array $a1  The first array
43     * @param array $a2  The second array
44     */ 
45     function Sum ($a1, $a2) { 
46         return array_merge($a1, $a2);
47     } 
48 } 
Source code below from:
Setting Up LAMP: Getting Linux, Apache, MySQL, and PHP Working Together
By Eric Rosebrock, Eric Filson, Eric Rosebrock, and Eric Filson
Published 22 July, 2004
Average rating

      Powells     Alibris

book/Chapter 11/database-test.php (10 lines)
5 $sql = mysql_query("SELECT * FROM my_table"); 
6  
7 while($row = mysql_fetch_array($sql)){
8    echo "Database Entry: ".$row['my_table_id']." | Value: ".$row['my_value']." | Date: ".$row['my_date']."<br />\n"; 
9 } 
Source code below from:
Beginning PHP 5 and MySQL: From Novice to Professional
By W. J. Gilmore
Published 21 June, 2004
Average rating

      Powells     Alibris

chapter20/sqlitearrayquery.php (11 lines)
2  
3    $sqldb = sqlite_open("pmnp.db"); 
4    $rows = sqlite_array_query($sqldb, "SELECT empid, name FROM employee");
5    foreach ($rows AS $row) { 
6       echo $row["name"]." (Employee ID: ".$row["empid"].")<br />"; 

chapter20/sqlitefetcharray-example1.php (13 lines)
5    $results = sqlite_query($sqldb, "SELECT * FROM employee"); 
6  
7    while ($row = sqlite_fetch_array($results,SQLITE_BOTH)) {
8       echo "Name: $row[1] (Employee ID: ".$row['empid'].")<br />"; 
9    } 

chapter20/sqlitefetcharray-example2.php (11 lines)
3    $sqldb = sqlite_open("pmnp.db"); 
4    $results = sqlite_query($sqldb, "SELECT * FROM employee"); 
5    while (list($empid, $name) = sqlite_fetch_array($results)) {
6       echo "Name: $name (Employee ID: $empid)<br />"; 
7    } 

chapter26/mysqlfetcharray-numerical.php (16 lines)
8    $result = mysql_query($query); 
9  
10    while ($row = mysql_fetch_array($result,MYSQL_NUM)) {
11       $name = $row[1]; 
12       $productid = $row[0]; 

chapter26/mysqlfetcharray.php (16 lines)
8    $result = mysql_query($query); 
9  
10    while ($row = mysql_fetch_array($result,MYSQL_ASSOC)) {
11       $name = $row['name']; 
12       $productid = $row['productid']; 
Source code below from:
Web Database Applications with PHP & MySQL, 2nd Edition
By Hugh E. Williams and David Lane
Published 16 May, 2004
Average rating

      Powells     Alibris

wda/appf/db.inc (35 lines)
12    } 
13  
14    function mysqlclean($array, $index, $maxlength, $connection)
15    { 
16      if (isset($array["{$index}"]))
17      { 
18         $input = substr($array["{$index}"], 0, $maxlength);
19         $input = mysql_real_escape_string($input, $connection); 
20         return ($input); 
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
23 } 24 25 function shellclean($array, $index, $maxlength) 26 { 27 if (isset($array["{$index}"])) 28 { 29 $input = substr($array["{$index}"], 0, $maxlength); 30 $input = EscapeShellArg($input); 31 return ($input);

wda/appf/mysql_sessions.inc (189 lines)
11   // and a second part. e.g.: 0.08344800 1000952237 
12  
13   // Convert the two parts into an array
14   $mtime = explode(" ", microtime()); 
15  
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
79 { 80 // Found a session - return the serialized string 81 $row = mysql_fetch_array($result); 82 return $row["session_variable"]; 83 }

wda/apph/example.h-1.php (36 lines)
20  
21    // (4) While there are still rows in the result set, fetch the current 
22    // row into the array $row
23    while ($row = mysql_fetch_array($result, MYSQL_NUM))
24    { 
25      // (5) Print out each element in $row, that is, print the values of 

wda/apph/example.h-2.php (36 lines)
20  
21    // (4) While there are still rows in the result set, fetch the current 
22    // row into the array $row
23    while ($row = mysqli_fetch_array($result, MYSQLI_NUM))
24    { 
25      // (5) Print out each element in $row, that is, print the values of 

wda/ch03/example.3-1.php (39 lines)
4 <head> 
5   <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> 
6   <title>Multi-dimensional arrays</title>
7 </head> 
8 <body bgcolor="#ffffff"> 
9 <h2>A two dimensional array</h2>
10 <?php 
11  
12   // A two dimensional array using integer indexes
13   $planets = array(array("Mercury", 0.39, 0.38),
14                    array("Venus", 0.72, 0.95),
15                    array("Earth", 1.0, 1.0),
16                    array("Mars", 1.52, 0.53) );
17  
18   // prints "Earth" 
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
20 ?> 21 22 <h2>More sophisticated multi-dimensional array</h2> 23 <?php 24 25 // More sophisticated multi-dimensional array 26 $planets2 = array( 27 "Mercury"=> array("dist"=>0.39, "dia"=>0.38), 28 "Venus" => array("dist"=>0.72, "dia"=>0.95),
Source code below from:
PHP 5 Fast & Easy Web Development (Fast & Easy Web Development)
By Julie C. Meloni
Published 11 May, 2004
Average rating

      Powells     Alibris

access_report.php (73 lines)
22  
23 //loop through results 
24 while ($row_ua = mysql_fetch_array($user_agent_res)) {
25     $user_agent = $row_ua['user_agent']; 
26     $user_agent_count = $row_ua['count']; 
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
42 43 //loop through results 44 while ($row_pn = mysql_fetch_array($page_name_res)) { 45 $page_name = $row_pn['page_name']; 46 $page_desc = $row_pn['page_desc'];

contact_menu_ch22.php (128 lines)
75         $get_contacts_bd ="SELECT id, f_name, l_name, MONTH(birthday) as month, DAYOFMONTH(birthday) as date FROM $table_name WHERE MONTH(birthday) = MONTH(NOW()) ORDER BY birthday"; 
76         $contacts_bd_res =@mysql_query($get_contacts_bd,$connection) or die(mysql_error()); 
77         while ($contacts_bd = mysql_fetch_array($contacts_bd_res)) {
78             $contact_id = $contacts_bd['id']; 
79             $contact_fname = $contacts_bd['f_name']; 

do_send_newsletter.php (35 lines)
22  
23     //loop through results and send mail 
24     while ($row = mysql_fetch_array($result)) {
25  
26         set_time_limit(0); 

pick_delcontact.php (70 lines)
32     //if results are found,loop through them 
33     //and make a form selection block 
34     while ($row =mysql_fetch_array($result)){
35         $id = $row['id']; 
36         $f_name = $row['f_name']; 

pick_modcontact.php (70 lines)
32     //if results are found,loop through them 
33     //and make a form selection block 
34     while ($row = mysql_fetch_array($result)){
35         $id = $row['id']; 
36         $f_name = $row['f_name']; 
Source code below from:
Essential PHP Tools: Modules, Extensions, and Accelerators
By David Sklar
Published 15 March, 2004
Average rating

      Powells     Alibris

1590592808-1/Chapter01/ex14.php (3 lines)
1 $sth = $dbh->query('SELECT * FROM ice_cream WHERE flavor LIKE ?', 
2      array($_REQUEST['flavor']));
3  

1590592808-1/Chapter01/ex15.php (6 lines)
1 $desserts = array('ice_cream' => 1, 'frozen_yogurt' => 1, 'sorbet' => 1);
2 if ($desserts[$_REQUEST['dessert']]) { 
3     $dbh->query('INSERT INTO ! (flavor) VALUES (?)', array($_REQUEST['dessert'], $_REQUEST['flavor']));
4 } else { 
5     print "No such dessert."; 

1590592808-1/Chapter01/ex16.php (2 lines)
1 $dbh->query("INSERT INTO dessert_pictures (flavor,image) VALUES (?,&)", 
2                      array('Rum Raisin','rum-raisin.jpeg'));

1590592808-1/Chapter01/ex18.php (2 lines)
1 $safe_for_select = str_replace(array('%','_'),array('\%','\_'),
2                               $_REQUEST['flavor']); 

1590592808-1/Chapter01/ex19.php (3 lines)
1 $flavor = str_replace(array('%','_'),array('\%','\_'),
2           $dbh->quote($_REQUEST['flavor'])); 
3 $sth = $dbh->query("SELECT * FROM ice_cream WHERE flavor LIKE $flavor"); 
Source code below from:
Advanced PHP Programming
By George Schlossnagle
Published 20 February, 2004
Average rating

      Powells     Alibris

ws/10-11.php (40 lines)
6   $name = $_REQUEST[name]; 
7   $project = new Project($name); 
8   if(array_key_exists("posted", $_POST)) {
9     $project->author = $_POST[author]; 
10     $project->short_description = $_POST[short_description]; 

ws/10-12.php (47 lines)
7   $name = $_REQUEST[name]; 
8   $project = new Project($name); 
9   if(array_key_exists("posted", $_POST)) {
10     $project->author = $_POST[author]; 
11     $project->short_description = $_POST[short_description]; 

ws/10-4.php (34 lines)
11   } 
12   function put($name, $tostore) { 
13     $storageobj = array('object' => $tostore, 'time' => time());
14     dba_replace($name, serialize($storageobj), $this->dbm); 
15   } 

ws/10-6.php (50 lines)
30     $cur->execute($this->userid); 
31     $rows = $cur->fetchall_assoc(); 
32     $ret = array();
33     foreach($rows as $row) { 
34       $ret[$row['position']] = $row['interest']; 

ws/10-7.php (40 lines)
13     } 
14     else { 
15       if(array_key_exists("USERINFO", $_COOKIE)) {
16         list($this->name, $this->userid, $this->interests) = 
17           unserialize($_cookie['USERINFO']); 
18       } 
19       else { 
20         throw new AuthException("no cookie"); 
21       } 
22     } 
23   } 
24   public function send() { 
25     $cookiestr = serialize(array($this->name, 
26                                $this->userid,  
27                                $this->interests)); 
Source code below from:
Learning PHP 5
By David Sklar
Published July, 2004
Average rating

      Powells     Alibris

LearningPHP5Code/AppendixB/example-B-05.php (18 lines)
12 print "preg_match_all() matched $match_count times.\n"; 
13  
14 print "preg_match() array: ";
15 var_dump($matches); 
16  
17 print "preg_match_all() array: ";
18 var_dump($matches_all); 

LearningPHP5Code/AppendixC/answer-10-1.php (42 lines)
15  
16 Here's the program that replaces the template fields with actual 
17 values. It stores the field names and values in an array and then uses
18 foreach() to iterate through that array and do the
19 replacement: 
20  
21 <?php 
22 $page = file_get_contents('article.html'); 
23 if ($page === false) { 
24     die("Can't read article.html: $php_errormsg"); 
25 } 
26 $vars = array('{title}' => 'Man Bites Dog',
27               '{headline}' => 'Man and Dog Trapped in Biting Fiasco', 
28               '{byline}' => 'Ireneo Funes', 

LearningPHP5Code/AppendixC/answer-10-2.php (69 lines)
30 } 
31  
32 // We'll count addresses with this array
33 $addresses = array();
34  
35 for ($line = fgets($in_fh); ! feof($in_fh); $line = fgets($in_fh)) { 

LearningPHP5Code/AppendixC/answer-10-4.php (75 lines)
42  
43 function validate_form() { 
44     $errors = array();
45  
46     // filename is required 

LearningPHP5Code/AppendixC/answer-10-5.php (27 lines)
2  
3 function validate_form() { 
4     $errors = array();
5  
6     // filename is required 
Source code below from:
Core PHP Programming, Third Edition
By Leon Atkinson and Zeev Suraski
Published 08 August, 2003
Average rating

      Powells     Alibris

corephp/10-11.php (92 lines)
9     //timeout after 5 seconds 
10     socket_set_option($socket, SOL_SOCKET, 
11         SO_RCVTIMEO, array('sec'=>5,'usec'=>0));
12  
13     //connect to the RtCW master server 
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
22 23 //get servers 24 $server = array(); 25 while(FALSE !== ($line = @socket_read($socket, 4096))) 26 {
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
34 $port = (ord(substr($line, $i+5, 1)) * 256) + 35 ord(substr($line, $i+6, 1)); 36 $server[] = array('ip'=>$ip, 'port'=>$port); 37 } 38 }

corephp/11-13.php (27 lines)
21  
22     //not scalar 
23     testScalar(array(1,2,3,4));
24     testScalar(new c); 
25     testScalar(fopen('/tmp/test', 'w')); 

corephp/11-18.php (12 lines)
1 <?php 
2     $list= array("milk", "eggs", "sugar");
3  
4     unset($list); 

corephp/11-19.php (8 lines)
1 <?php 
2     //create an array
3     $myArray = array(
4         "Name"=>"Leon Atkinson", 
5         "Profession"=>array("Programmer", "Author"),
6         "Residence"=>"Martinez, California" 
7     ); 

corephp/11-20.php (13 lines)
1 <?php 
2     $location = array('Leon Atkinson'=>'home',
3         'john villarreal'=>'away', 
4         'leon atkinson'=>'away', 
5         'Carl porter'=>'home', 
6         'Jeff McKillop'=>'away', 
7         'Rick Marazzani'=>'away', 
8         'bob dibetta'=>'away', 
9         'Joe Tully'=>'home' 
10         ); 
11  
12     print_r(array_change_key_case($location, CASE_UPPER));
13 ?> 
Source code below from:
Usable Shopping Carts
By Jon Stephens, Jody Kerr, and Clifton Evans
Published 07 July, 2003
Average rating

      Powells     Alibris

tunein/html/checkout.php (435 lines)
295   </tr> 
296 <?php 
297         $item_types = array("CDs","Cassettes","Vinyl LPs","Tickets");
298         $ship_total = 0; 
299         for($j=0;$j<4;$j++) 

tunein/html/checkout1.php (219 lines)
83   </tr> 
84 <?php 
85     $item_types = array("CDs","Cassettes","Vinyl LPs","Tickets");
86     $ship_total = 0; 
87     for($j=0;$j<4;$j++) 

tunein/html/checkout2.php (292 lines)
39     $is_comment = "/[a-zA-Z0-9\.\,;:%&#@!\^-_~`\"'\[\]\{\}\*\/\?\(\)\n\r]/"; 
40  
41     $requirements = array("required","alphabetic","address","alphanumeric","nospace",
42                           "integer","decimal","minlength","maxlength","uszip", 
43                           "usphone","email","currency","percent","comment"); 

tunein/html/otherform.php (184 lines)
28  
29   $s_result = mysql_query($s_query); 
30   $s_row = mysql_fetch_array($s_result);
31  
32   $email = $s_row["customer_email"]; 

tunein/html/search.php (223 lines)
103       else 
104       { 
105         while( $row = mysql_fetch_array($result) )
106         { 
107           switch($section) 
Source code below from:
PHP MySQL Website Programming: Problem - Design - Solution
By Chris Lea, Mike Buzzard, Dilip Thomas, and Jessey-White Cinis
Published March, 2003
Average rating

      Powells     Alibris

DVD Life/_lib/_base/config.php (54 lines)
45  
46 /* assign instance variables */ 
47 $EXCEPTS = array();                                    // exceptions array
48 $ERRORS = array();                                     // errors array
49 $FILES = array("jpg", "gif", "png");                   // file types array
50 $FORMOK = true;                                       // form status 
51  

DVD Life/_lib/_base/elements.php (226 lines)
56 } 
57  
58 // write a pre-formatted array contents
59 function dump($aArgs) { 
60     print "<pre>"; 
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
69 ?> 70 <br /> 71 <?php if (is_array($aData)) { ?> 72 <table width="608" border="0" cellpadding="0" cellspacing="0"> 73 <tr>
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
84 while ($i < count($aData)) { 85 !strcmp("FFFFFF", $bg) ? $bg = "F6F6F6" : $bg = "FFFFFF"; 86 $aState = array("act", "deact"); 87 ?> 88 <tr>

DVD Life/_lib/_base/funcs.php (68 lines)
20      
21     global $EXCEPTS; 
22     array_push($EXCEPTS, $sMsg);
23 } 
24  
25 // catch page error 
26 function catchErr($sMsg) { 
27      
28     global $ERRORS; 
29     array_push($ERRORS, $sMsg);
30 } 
31  

DVD Life/_lib/_base/handlers.php (99 lines)
48      
49     global $FILES; 
50     $sExt = strtolower(array_pop(explode(".", $_FILES[$sVal]["name"])));
51      
52     if (!in_array($sExt, $FILES)) {
53          
54         $sTypes = ""; 

DVD Life/_lib/_classes/class.accounts.php (836 lines)
81      * sets session values for a user 
82      * 
83      * @param array $aArgs session data
84      * @access private 
85      */ 
86     function _setSession($aArgs) { 
87          
88         // create string from account array values
89         $sVal = implode("|", $aArgs); 
90          
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
186 * authenticate user account 187 * 188 * @param array $aArgs user login values 189 * @return boolean 190 * @access private
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
236 } 237 238 // assign account array values 239 $aAccount = array($aRow["account_id"], $aRow["account_screenname"], 240 $aRow["account_email"], $aRow["account_pass"]); 241
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
297 * get the user account session values 298 * 299 * @return array session data 300 * @access public 301 */ 302 function getSession() { 303 304 // check for account session cookie 305 if (isset($_COOKIE["cACCOUNT"])) { 306 307 // apply account session values to an array 308 $aSess = explode("|", $_COOKIE["cACCOUNT"]); 309 $return["Account Id"] = $aSess[0];
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
325 function validateSession() { 326 327 // if the session array is active 328 if ($aUser = $this->getSession()) { 329
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
366 * send an account password reminder to the associated user 367 * 368 * @param array $aArgs user login data 369 * @return boolean 370 * @access public
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
424 * login to a user account 425 * 426 * @param array $aArgs user login data 427 * @return boolean 428 * @access public
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
444 * get a single account by account id 445 * 446 * @return array account data 447 * @access public 448 */
Source code below from:
PHP Graphics Handbook
By Jason E. Sweat, Allan Kent, and Mitja Slenc
Published 25 February, 2003
Average rating

      Powells     Alibris

ch-5,6,7/Ch05/3d/3dlib.php (448 lines)
41 function SmoothMap($heights) 
42 { 
43     $result=array();
44     foreach($heights as $x => $row) 
45         foreach($row as $y => $dist) { 
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
64 if ($dist>0.0) { 65 $dist=sqrt($dist); 66 return array($x/$dist, $y/$dist, $z/$dist); 67 } 68 return array(0,0,1); 69 } 70 71 class DirectionalLight 72 { 73 var $vec; 74 function DirectionalLight($nx, $ny, $nz, $r=255, $g=255, $b=255) { 75 $this->vec=array_merge(Normalize($nx, $ny, $nz), array($r/255.0, $g/255.0, $b/255.0)); 76 } 77 function GetLightVector($x, $y, $z)
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
85 function PointLight($x, $y, $z, $r=255, $g=255, $b=255) 86 { 87 $this->pos=array($x, $y, $z); 88 $this->col=array($r/255.0, $g/255.0, $b/255.0); 89 } 90 function GetLightVector($x, $y, $z) 91 { 92 return array_merge(Normalize( $this->pos[0]-$x, $this->pos[1]-$y, $this->pos[2]-$z), $this->col); 93 } 94 }
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
107 $col=imagecolorsforindex($this->image, imagecolorat($this->image, $x, $y)); 108 109 return array( 110 $col["red"] *$tmp[0]/255.0, 111 $col["green"]*$tmp[1]/255.0,
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
118 { 119 var $mats; 120 function MaterialSum() { $this->mats=array(); } 121 function Add($mat) { $this->mats[]=$mat; } 122 function GetColor($x, $y, $z, $normal, $lights)
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
129 $b+=$ab; 130 } 131 return array($r, $g, $b); 132 } 133 }

ch-5,6,7/Ch05/3d/chiseling.php (64 lines)
21 $mat->Add(new MaterialSpecular(255, 255, 255, 20)); 
22  
23 $mats=array("default" => $mat);
24 $lights=array(new DirectionalLight(-4, -6, 10));
25  
26 list($distances, $maxdist)=MakeDistanceMap($imagein, "SignBG"); 

ch-5,6,7/Ch05/3d/graph.php (45 lines)
14 $mat->Add(new MaterialSpecular(255, 255, 255, 20)); 
15  
16 $mats=array("default" => &$mat);
17 $lights=array(new DirectionalLight(-6, -4, 8));
18  
19 list($distances, $maxdist)=MakeDistanceMap($im, "IsGray"); 

ch-5,6,7/Ch05/3d/phongterms.php (86 lines)
42 $horizon->Add(new MaterialHorizon(100, 100, 100, -100, -100, -100)); 
43  
44 $mats=array(
45     "ambient" => new MaterialAmbient(80, 80, 100), 
46     "diffuse" => new MaterialDiffuse(255, 128, 50), 
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
56 $white=imagecolorresolve($imageout, 255, 255, 255); 57 58 $lights=array(); 59 $lights[]=new DirectionalLight(-4, -6, 10); 60 61 foreach($mats as $name => $mat) { 62 if ($name=="combined") { 63 $imageout=imagecreatefrompng("sign_shadow.png"); 64 } else { 65 imagefilledrectangle($imageout, 0, 0, $sx, $sy, $white); 66 } 67 RenderNormals($imagein, $imageout, $heights, $normals, array("default" => $mat), $lights); 68 imagepng($imageout, "sign_".$name.".png"); 69 }

ch-5,6,7/Ch05/3d/smoothing.php (60 lines)
18 $mat->Add(new MaterialDiffuse(215, 215, 215)); 
19  
20 $mats=array("default" => $mat);
21 $lights=array(new DirectionalLight(-4, -6, 10));
22  
23 list($distances, $maxdist)=MakeDistanceMap($imagein, "SignBG"); 
Source code below from:
Dreamweaver MX: Advanced PHP Web Development
By Glasshaus Author Team
Published January, 2003
Average rating

      Powells     Alibris

Documents and Settings/matthewma/My Documents/phpdwmx/error/errorhandler.php (51 lines)
9     $date = date("d/m/Y"); 
10     $time = date("H:i"); 
11 $errorType = array (1=>"Error", 2=>"Warning", 4=>"Parsing Error", 8=>"Notice", 16=>"Core Error", 32=>"Core Warning", 64=>"Compile Error",  128=>"Compile Warning", 256=>"User Error", 512 =>  "User Warning", 1024=>"User Notice");
12  
13 $outputHtml = " 

Documents and Settings/matthewma/My Documents/phpdwmx/graphics/jpgraph_example.php (47 lines)
13 $row_ChartRS = mysql_fetch_assoc($ChartRS); 
14 $totalRows_ChartRS = mysql_num_rows($ChartRS); 
15 $datay=array();
16 $labelx=array();
17  
18 do {    
19   array_push($datay, $row_ChartRS['totalcount']);
20   array_push($labelx, $row_ChartRS['name']);
21 } while ($row_ChartRS = mysql_fetch_assoc($ChartRS)); 
22  

Documents and Settings/matthewma/My Documents/phpdwmx/graphics/primitives_example.php (17 lines)
6   imagefilledrectangle($myImage, 25, 25, 275, 275, $white); 
7   imageline($myImage, 150, 30, 150, 270, $black); 
8   $myTriangle = array (50, 50, 50, 100, 100, 100);
9   imagepolygon($myImage, $myTriangle, 3, $black); 
10   imagerectangle($myImage, 50, 150, 100, 250, $black); 

cms/class/adminArticles.php (301 lines)
83     $query .=" FROM tblmainmenu ORDER BY position ASC"; 
84     $result = $this->DB_executeQuery($query, $this->articleLink); 
85     $tempArray['label'] = "Root";
86     $tempArray['id'] = 0;
87     $this->menuPrimary[] = $tempArray;
88     while($row = mysql_fetch_assoc($result)){ 
89         $tempArray['label'] = $row['label'];
90         $tempArray['id'] = $row['id'];
91         $this->menuPrimary[] = $tempArray;
92     }    
93 } 
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
259 260 function displayImages(){ 261 if(is_array($this->images)){ 262 $count = 1; 263 foreach($this->images as $image){

cms/class/adminMenu.php (185 lines)
16     var $moveButtons; 
17     var $adminButtons; 
18     var $menuArray;
19     var $currentPosition; 
20     var $numRecords; 
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
53 } 54 55 function createMenuArray(){ 56 $query = "SELECT id,label,position,link FROM tblmainmenu ORDER BY position ASC"; 57 $result = $this->DB_executeQuery($query,$this->menuLink); 58 $this->numRecords = $this->DB_getRecords($result); 59 for($count=1;$count<=$this->numRecords;$count++){ 60 $row = mysql_fetch_assoc($result); 61 $this->menuArray[$count] = $row['id']; 62 if($row['id'] == $_POST['menu']){ 63 $this->currentPosition = $row['position'];
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
68 function changePosition($direction){ 69 $selected = $_POST['menu']; 70 $this->createMenuArray(); 71 $currentPosition = $this->currentPosition; 72 if($direction == "up"){
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
79 if(($swapPosition > 0) && ($swapPosition <= $this->numRecords)){ 80 $query = sprintf("UPDATE tblmainmenu SET position ='%s' WHERE id = '%s'", 81 $swapPosition, $this->menuArray[$currentPosition]); 82 $result = $this->DB_executeQuery($query,$this->menuLink); 83 $query = sprintf("UPDATE tblmainmenu SET position ='%s' WHERE id = '%s'", 84 $currentPosition, $this->menuArray[$swapPosition]); 85 $result = $this->DB_executeQuery($query,$this->menuLink); 86 }
Source code below from:
PHP Bible, 2nd Edition
By Tim Converse and Joyce Park
Published 11 September, 2002
Average rating

      Powells     Alibris

PHPBible_2ndEd/ch11/wc_handler_array.php (74 lines)
1 <?php 
2  
3 // This is the array where we keep our exercise names
4 $name_array = array(
5                     0 => 'Biking/cycling', 
6                     1 => 'Running', 
7                     2 => 'Soccer/football', 
8                     3 => 'Stairclimber', 
9                     4 => 'Weightlifting' 
10                   ); 
11  
12 // This is the array where we keep our duration data
13 $duration_array = array(
14                     0 => '5 hours and 40 minutes', 
15                     1 => '4 hours and 30 minutes', 
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
20 21 // Now step through the exercises and see which ones they chose 22 if (is_array($_POST) && count($_POST) > 1) { 23 $message = ''; 24 foreach ($_POST['exercise'] as $key => $val) { 25 if ($val == 1) { 26 $exercise_name = $name_array[$key]; 27 $hours = $duration_array[$key]; 28 $message .= 29 "</P>\n<P>It would take $hours of $exercise_name " .
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
36 $message = 'Ummm, did you pick an exercise?'; 37 } //If you don't have this test, an empty form will cause an error. 38 //Usually you'd test an array for a count of 0, but here 39 //there is 1 automatic POST array element -- $_POST['submit']. 40 41

PHPBible_2ndEd/ch02/techbizbook.php (41 lines)
19    $query = "SELECT Blurb FROM Org WHERE OrgName = '$org'"; 
20    $qresult = mysql_query($query) or die(mysql_error()); 
21    $blurb = mysql_fetch_array($qresult) or die(mysql_error());
22    print("$blurb[0]"); 
23    ?> 
24    </TD></TR> 
25    <TR><TD ALIGN=LEFT> 
26       <TABLE BORDER=1 CELLPADDING=3> 
27       <?php 
28       $query2 = "SELECT ID, Title, AuthorFirst, AuthorLast FROM bookinfo WHERE OrgName='$org' ORDER BY AuthorLast"; 
29       $qresult2 = mysql_query($query2) or die(mysql_error()); 
30       while ($titlelist = mysql_fetch_array($qresult2)) {
31          $bookID = $titlelist[0]; 
32          $title = $titlelist[1]; 

PHPBible_2ndEd/ch06/listing6_1.php (32 lines)
4 $type_examples[2] = "a non-numeric string"; 
5 $type_examples[3] = "49.990 (begins with number)"; 
6 $type_examples[4] = array(90,80,70);
7  
8 print("<TABLE BORDER=1><TR>"); 
9 print("<TH>Original</<TH>"); 
10 print("<TH>(int)</<TH>"); 
11 print("<TH>(double)</<TH>"); 
12 print("<TH>(string)</<TH>"); 
13 print("<TH>(array)</<TH></TR>");
14  
15 for ($index = 0; $index < 5; $index++) 
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
26 print("<TD>$converted_var</TD>"); 27 $converted_var = 28 (array) $type_examples[$index]; 29 print("<TD>$converted_var</TD></TR>"); 30 }

PHPBible_2ndEd/ch08/listing8_1.php (85 lines)
69 print("Original message is: $original<BR>"); 
70  
71 $coding_array = array('add_1',
72                       'sub_1', 
73                       'swap_2', 
74                       'swap_26'); 
75 for ($count = 0; 
76      $count < sizeof($coding_array);
77      $count++) 
78 { 
79   $code = $coding_array[$count];
80   $coded_message = 
81      string_cipher($original, $code); 

PHPBible_2ndEd/ch08/tour_brochure.php (20 lines)
1 <?php 
2 function tour_brochure($info_array)
3 { 
4 $city = 
5  IsSet($info_array['city']) ?
6   $info_array['city'] : "Gotham City";
7 $desc = 
8  IsSet($info_array['desc']) ?
9   $info_array['desc'] : "great metropolis";
10 $how_many = 
11  IsSet($info_array['how_many']) ?
12   $info_array['how_many'] : "dozens";
13 $of_what = 
14  IsSet($info_array['of_what']) ?
15   $info_array['of_what'] : "costumed villains";
16  
17 print("$city is a $desc filled with 
Source code below from:
Web Database Applications with PHP & MySQL
By Hugh E. Williams and David Lane
Published March, 2002
Average rating

      Powells     Alibris

customer_receipt.php (87 lines)
30      
31     // There is only one matching row 
32     $row = @ mysql_fetch_array($result);
33  
34     echo "\n<h1>Account details for <font color=\"red\">" . $row["email"] . "</font></h1>\n"; 

example.2-4.php (56 lines)
21 <html> 
22 <head> 
23   <title>Multi-dimensional arrays</title>
24 </head> 
25 <body bgcolor="#ffffff"> 
26 <h2>A two dimensional array</h2>
27 <?php 
28  
29   // A two dimensional array using integer indexes
30   $planets = array(array("Mercury", 0.39, 0.38),
31                    array("Venus", 0.72, 0.95),
32                    array("Earth", 1.0, 1.0),
33                    array("Mars", 1.52, 0.53) );
34  
35   // prints "Earth" 
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
37 ?> 38 39 <h2>More sophisticated multi-dimensional array</h2> 40 <?php 41 42 // More sophisticated multi-dimensional array 43 $planets2 = array( 44 "Mercury"=> array("dist"=>0.39, "dia"=>0.38), 45 "Venus" => array("dist"=>0.39, "dia"=>0.95),

example.4-1.php (59 lines)
41  
42    // (3) While there are still rows in the result set, 
43    // fetch the current row into the array $row
44    while ($row = mysql_fetch_row($result)) 
45    { 

example.4-10.php (137 lines)
50  
51       // Retrieve the varieties ... 
52       while ($row = @ mysql_fetch_array($result))
53          // ... and print each one 
54          echo " " . $row["variety"]; 
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
89 90 // Process the three new wines 91 while ($row = @ mysql_fetch_array($result)) 92 { 93 // Print a heading for the wine

example.4-11.php (154 lines)
50  
51       // Retrieve the varieties ... 
52       while ($row = @ mysql_fetch_array($result))
53          // ... and print each one 
54          echo " " . $row["variety"]; 
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
68 69 // Retrieve the cheapest price 70 $row = @ mysql_fetch_array($result); 71 72 // Print the pricing information
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
119 120 // Process the three new wines 121 while ($row = @ mysql_fetch_array($result)) 122 { 123 // Print a heading for the wine
Source code below from:
Programming PHP
By Rasmus Lerdorf and Kevin Tatroe
Published March, 2002
Average rating

      Powells     Alibris

progphp-examples/ch03/3-7.php (5 lines)
1 $lambda =create_function('$a,$b','return(strlen($a)-strlen($b));'); 
2 $array = array('really long string here,boy', 'this', 'middling length',
3                'larger'); 
4 usort($array,$lambda);
5 print_r($array);

progphp-examples/ch05/5-1.php (18 lines)
1 $ages = array('Person'  => 'Age',
2               'Fred'    => 35, 
3               'Barney'  => 30, 

progphp-examples/ch05/5-2.php (28 lines)
1 <?php 
2   function have_required($array, $required_fields) {
3     foreach ($required_fields as $field) { 
4       if (empty($array[$field])) return false;
5     } 
6  
7     return true; 
8   } 
9  
10   if ($submitted) { 
11     echo '<p>You '; 
12     echo have_required($_POST, array('name', 'email_address'))
13          ? 'did' : 'did not'; 
14     echo 'have all the required fields.</p>'; 

progphp-examples/ch05/5-3.php (45 lines)
11 } 
12  
13 $values = array('name'          => 'Buzz Lightyear',
14                 'email_address' => 'buzz@starcommand.gal', 
15                 'age'           => 32, 

progphp-examples/ch05/5-4.php (34 lines)
1 $call_trace = array();
2  
3 function enter_function($name) { 
4   global $call_trace; 
5   array_push($call_trace, $name);     // same as $call_trace[] == $name
6   echo "Entering $name (stack is now:". join('->',$call_trace) . ')<br />'; 
7 } 
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
10 echo 'Exiting<br />'; 11 global $call_trace; 12 array_pop($call_trace); // we ignore array_pop()'s return value 13 } 14
Source code below from:
PHP Advanced for the World Wide Web Visual QuickPro Guide
By Larry Ullman
Published 15 December, 2001
Average rating

      Powells     Alibris

1/script_01_01.php (80 lines)
18 $f = '2001/picks_' . W . '_Winners_.txt'; / 
19 if ($fp = @fopen ($f, "w")) {  
20 array_walk ($w, 'write_data', $fp); 
21 fclose ($fp);  
22 echo 'The winners have been stored!<br></br>'; 
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
39 } 40 } 41 $p = array(); 42 $d = '2001/'; 43 $dp = opendir ($d);
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
56 } 57 } 58 $r[$k] = array ('ws' => $ws, 'ls' => $ls); 59 } 60 ksort ($r);
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
70 $f2 = '2001/results_' . W . '_.txt'; 71 if ($fp2 = @fopen ($f2, "w")) { 72 array_walk ($r, 'write_results', $fp2); . 73 fclose ($fp2); // Close the file. 74 echo 'The results have been stored.<br></br>';

1/script_01_02.php (117 lines)
26 if ($fp = @fopen ($file, "w")) {  
27  
28     array_walk ($winners, 'write_data', $fp); 
29     fclose ($fp);  
30  
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
58 } 59 60 $picks = array(); 61 62 $directory = '2001/';
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
82 } 83 84 $results[$key] = array ('wins' => $wins, 'losses' => $losses); 85 } 86
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
105 if ($fp2 = @fopen ($file2, "w")) { 106 107 array_walk ($results, 'write_results', $fp2); . 108 fclose ($fp2); // Close the file. 109 echo 'The results have been stored.<br></br>';

1/script_01_03.php (150 lines)
44 $file = '2001/picks_' . WEEK . '_Winners_.txt'; // Identify the file in the format 'picks_1_Winners_.txt'. 
45  
46 if ($fp = @fopen ($file, "w")) { // Read the file into an array.
47  
48     array_walk ($winners, 'write_data', $fp); // Send the entire array to the write_data function.
49     fclose ($fp); // Close the file. 
50  
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
83 } 84 85 $picks = array(); // Initialize the main variable. 86 87 $directory = '2001/';
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
95 /* ----------------------------- */ 96 97 while (list ($key, $value) = each ($picks)) { // Loop through the main array. 98 99 $wins = 0; // Set to 0 for each array. 100 $losses = 0; // Set to 0 for each array. 101 102 while (list ($key2, $value2) = each ($value)) { // Loop through each user's array. 103 104 $value2 = substr ($value2, 0, (strlen($value2) - 1)); // Remove the return character.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
111 } 112 113 $results[$key] = array ('wins' => $wins, 'losses' => $losses); // Store each users performance in an array. 114 } 115 116 ksort ($results); // Aphabetize the array. 117 118

1/script_01_05.php (52 lines)
10 $file = '2001/week' . $week . '.txt'; // Identify the file based upon which week it is. 
11  
12 if ($games = @file ($file)) { // Read the file into an array.
13  
14     // If it read the file, print the form. 
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
21 '; 22 23 foreach ($games as $key => $array) { // Use an array to print out each game. 24 25 if ($key != 0) { // Don't print the Away Home line. 26 27 $second_array = explode ("\t", $array); // Turn each line of the array into its own array. 28 $away = $second_array[0]; // The first item is the Away team. 29 $home = substr ($second_array[1], 0, (strlen($second_array[1]) - 1)); // The second item is the Home team but delete the return character. 30 31 echo " <tr align=\"center\" valign=\"top\">

1/script_01_06.php (33 lines)
22  
23     fputs ($fp, "Dummy Line\n"); // Create a dummy line. 
24     array_walk ($picks, 'write_data', $fp); // Send the entire array to the write_data function.
25     fclose ($fp); // Close the file. 
26     echo 'Your picks have been stored.'; 
Source code below from:
Foundation PHP for Flash
By Steve Webster
Published September, 2001
Average rating

      Powells     Alibris

phpforflash/chapter2/for_array.php (10 lines)
1 <? 
2 $name = array('Steve Webster', 'Alan McCann', 'Kev Sutherland', 'Jim Hannah');
3  
4 for ($index = 0; $index < count($name); $index++) 

phpforflash/chapter2/multi_array.php (20 lines)
6  
7  
8     // Loop to traverse elements of $users array
9     foreach($users as $key => $value) { 
10         // Output 
11         echo "User $key<br>\n"; 
12  
13         // Loop to traverse each sub-array
14         foreach($value as $key2 => $value2) { 
15             echo "  $key2: $value2<br>\n"; 

phpforflash/chapter2/sort_array.php (11 lines)
1 <? 
2  $reviewers = array("Gareth", "Stef", "Pete", "Jake");
3  
4 sort($reviewers); 

phpforflash/appendix/basket.php (131 lines)
7         // Class properties (Only one this time) 
8          
9         var $items; // This property will hold all of the contents of the basket.  Each item in this array will be an instance of the Item object
10  
11         // Class Methods 
12          
13         // Constructor Function 
14         function Basket() { 
15             // Set up $items as an array
16             $this->items = array();
17         } 
18          
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
25 $newItem = new Item($description, $price); 26 27 // Add the object to the $items array 28 $this->items[] = $newItem; 29 30 } 31 32 33 // Remove all items from the basket 34 function removeAll() { 35 // To do this, we reset the $items array 36 $this->items = array(); 37 } 38
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
43 print "&basketTotal=£".$this->getTotalPrice(); 44 45 // Rewind the $items array back to the beginning 46 reset($this->items); 47
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
68 $total = 0; 69 70 // Rewind the $items array back to the beginning 71 reset($this->items); 72

phpforflash/appendix/products.php (26 lines)
1 <? 
2     // Set up the products in two arrays
3  
4     $productName[]="Shoes"; 

Not satisfied? Try this search biased towards software and programming:
Google