| 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. | ||
| ||
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]; | ||
| ||
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 | ||
| ||
phphacks/amazon/index.php (121 lines) 34 global $amazon; 35 36 $out = array(); 37 $products = $amazon->searchKeyword($keyword, "books", 1); 38 if( $products != null ) 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 phphacks/checklinks/checklinks.php (34 lines) 11 print( $doc ); 12 13 $badlinks = array(); 14 foreach( $found[1] as $link ) 15 { | ||
| ||
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 ?> | ||
| ||
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' 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 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"; 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.'; | ||
| ||
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 | ||
| ||
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;} | ||
| ||
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) { 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; | ||
| ||
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 ) { 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 ) { | ||
| ||
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 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 } 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 | ||
| ||
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 } | ||
| ||
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 } | ||
| ||
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']; | ||
| ||
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); 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 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" | ||
| ||
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']; 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']; | ||
| ||
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"); | ||
| ||
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)); | ||
| ||
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 | ||
| ||
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 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 ?> | ||
| ||
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) | ||
| ||
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>"; 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 | ||
| ||
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) { 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), 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"); | ||
| ||
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 } cms/class/adminMenu.php (185 lines) 16 var $moveButtons; 17 var $adminButtons; 18 var $menuArray; 19 var $currentPosition; 20 var $numRecords; | ||
| ||
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', 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++) 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 | ||
| ||
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" 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"]; 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"]; | ||
| ||
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 } | ||
| ||
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>'; 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 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 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. 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.'; | ||
| ||
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 phpforflash/appendix/products.php (26 lines) 1 <? 2 // Set up the products in two arrays 3 4 $productName[]="Shoes"; | ||