Efficiency Question: Overwrite Array Value, Or Ask If It Is Set?
While looping through an array I extract all keys on the fly, as in this
example:
$data = array(
array('name' ='Helen', 'age' =ཤ'),
array('name' ='Mark', 'email' ='mark@xyz.com', 'age' =ྖ'),
);
$keys = array();
foreach ($data as $row) {
foreach ($row as $key =$value) {
// do other things here
$keys[$key] = 1;
}
}
$column_names = array_keys($keys);
Now my question is about the line
$keys[$key] = 1;
This overwrites existing entries and thus creates a set of unique keys.
This could also be done without overwriting:
if (!isset($keys[$key])) $keys[$key] = 1;
So I wonder which is more efficient - overwriting the array entry at
every loop, or checking for it with the if statement.
View Complete Forum Thread with Replies
See Related Forum Messages: Follow the Links Below to View Complete Thread
Overwrite To File
I a php noob so sorry if this is a stupid question, I have a little code that puts some data in a file which works very well. I want to instead of append to the file I want to overwrite the contents of it. ? -------------------existing code------------------- <?php $filename = "justatest.txt"; $output = "SOME_DATA_HERE"; $filehandle = fopen($filename, 'a'); fwrite($filehandle, $output); fclose($filehandle); ?>
Can't Overwrite Return-path
I want to use mail() function but I can't overwrite Retun-Path info. Most mail servers overwrite the 'Return-path' header sent by the PHP mail() function by a default email address (httpd@hostingcompany.com or apache@domain.org). I tried : $headers = 'From: MyName<'.$from.'> ' $headers .= 'Return-Path: MyName<'.$from.'> ' even: $headers,"-f".$from
How To Overwrite Default Php Installation
On my linux system php seems to have been installed by default. When I type: "which php" it tells me /usr/bin/php I installed php and it has put an executable in the /usr/local/bin/php "which php" still says /usr/bin/php "whereis php" php: /etc/php.ini /usr/bin/php /usr/local/bin/php /usr/local/lib/php /usr/local/lib/php.ini /usr/local/lib/php -v shows the new version but php -v shows the old version. How can I correct this problem? I want to run the command php -v and it shows the newest version. I have already tried removing /etc/php.ini /usr/bin/php
Overwrite Image That Was Already Uploaded
When a user uploads an image from a form, the image is loaded to a directory on my server. If the user uploads an image with the same filename as one that already exists in the uploaded folder, they receive this error: Warning: copy(image path/image name.jpg) [function.copy]: failed to open stream: Permission denied in /var/www/uploadpage.php on line 22 Is there a way to hide this error or to allow the user to overwrite the existing image?
Overwrite Uploaded Photo
i;m using this code to upload photos it works great basic but great, what i want to do is when a user uploads a photo the previuos one is deleted, i tried a few unlink codes but it never workjed out, Code:
Include() Efficiency
Does anyone know if there is a performance difference between including a single "large" file, or including several smaller files that, in aggregate, contain the same code? I guess the real question is how much overhead is involved in calling include()?
Filesize() Efficiency
I'm constructing a page that contains a list of files that can be downloaded - The file details (name, description, date) are stored on a database (mySQL). When displaying the file details on HTML I use filesize() to display the size of each file. Is this really inefficient? Would it be better to store the size of the file on the database instead. What's kind of performance difference are we talking about.
Efficiency Of Mysql_close()
I am working on a script for PHP that handles mysql_connections. Right now, each time I query the database, i open the connection using mysql_connect(), and after I get my resource result, I use mysql_close(). I have heard from many people that it is common practice to open a connection at the beginning of the script, and since the connection closes at the end of the script, it is then closed. My question is this: Which is the better way? To open the script at the top, and then let the connection close at the bottom? As this may be a controversial issue, and if no answer is found, what are the advantages? Does anyone know if the resources used, and the time elapsed to make a db connection is significant enough to warrant leaving the connection open the entire time?
PHP And JS Interaction - Efficiency?
I'm working on an interesting web app and here's a situation I'm going to get to: * User performs an action, which starts this "session"... * During this "session", user will be sending requests (performing actions) to the server every 3 secs, or 5 secs. These are AJAX (xmlHttpRequest) requests. * This could go on for 5~10 times before this "session" ends. (when I say "session", it has nothing to do with cookies, I just mean the word "session" in literal meaning) Now, due to the information needed to perform every action, each request would need to do a MySQL query, grab some information, then do some calculation, and write to the db. If we consider possibly large user traffic, then I'd want to do this as efficiently as possible. I can do this the normal way -- have xmlHttpRequest send to a php script, then it will go through and do all that needs to be done. (script begins -> SQL read -> processing code -> SQL write -> output to client -> script ends) Is there any ways I could make this more efficient? What I don't know is if it's possible to make it only one script execution, while it waits for new user actions. Effectively, this means: script begins -> SQL read -> processing code -> SQL write -> output to client -> wait for next event -> processing code, SQL write, output and repeat until last action -> script ends This saves 1 MySQL query for every action done, because only one read initially is needed for the entire lifetime in my specific case. However, how can this be done at all? The PHP script and the JS would need to have some kind of interaction, more than just the xmlHttpRequest. (because if a request was made, then it's starting a new php script execution) I thought about using cookies, having JS set some cookies for each action done, and have the php script read it every 5 secs -- but that creates sync'ing problem and I don't think JS can set cookies before the whole page refreshes, anyway.
Overwrite File To Update Contents
I'm hoping someone can help me figure this little problem i am having with the following PHP script... i have registration form that a person can use to sign up for email, and when they submit there information, i have a script that is suppose to write to a text file the username and email address... however, is there a way to delete the contents of the text file or overwrite it completely with all the usernames and email addresses in the database(which was already there to begin with) plus the new person's username and email address???? the idea here is to have the most current info from the database be written to the text file when someone signs up for email... the following code snippet is the code that is suppose to place the new user's username and email address...
PHP5, DOM, XPath - Overwrite Elements Or Not?
I'm playing around with PHP5, DOM, and XPath. Is it possible to overwrite elements in an xml document? From my understanding it is not possible as values are "immutable". Is this correct? I assume I would just make a copy of an xml document and save over the original file.
A Question About Efficiency & Performance
I am developing a site which will be very dynamic. Most of the displayed content will come from a database (MySql) via PHP. Some types of pages will change frequently (something like a forum page which is always having new content added to it) and others will only change once a day (a new news item gets added, etc.). Although I can optimise my queries and my PHP scripts, there is still the potential for the site to get congested, once a large number of people start accessing it. The question is how do I make sure it performs well? There are several options I might consider, such as: - don't do anything, but rely on server caching. Is PHP / Apache caching any good? - Periodically "publish" my PHP-generated pages to flat HTML pages and serve them up instead of the PHP. - Other things?
Variables + Script Efficiency
I'm used to C++ and I find that I have been spending a lot of time "optimizing" my PHP scripts (or so I think, but I'm not sure how much of a difference I am making). My question is, is there any significant performance difference in the following 3 (silly) code bits:Accessing array with string index: PHP Code:
Efficiency Of File Vs Database
I have a program that reads the contents of a file (1 line, 5 '|' seperated items). Every so often (between twice a day, and 200 times a day), it rewrites the contents of that file. I also do a few database update queries whenever the file is written. I only open up the database connector if I need to update the database. The script itself runs every 30 seconds. My question, is that is it faster and more efficient to read the file every time, or open the database connector and make a query? The file name never changes, and I read the whole file at one time (679 bites).
Efficiency Of Multiple Includes
I've been wondering this for a while and have searched everywhere for it: I really like to break my code up into files that are less than a million lines long, so I've divided my site into "switch" files (so called because they redirect the path of execution like an old telephone switch board). I figure this could win out in the end because PHP doesn't parse include files that aren't relevant to the current script path (i.e., it won't parse "this.php" in this case: if (1 == 0) { include 'this.php'; }), so it can save a lot of parsing, but at the same time, I don't know how the include mechanism works, and I don't want to burden the server unnecessarily by including every word in a separate file. What I'm looking for is a reasonable rule for the optimum balance of includes and file length. Here's my example (please ignore any violations to best-practices, as this is a speedily-contrived example): Code:
Selecting Array Rows Based On An Array Of Field=>values
Here's the code i have: $db = array(); //main array $db['main'] = array(); //table `main` $db['main'][] = array('id'=>0, 'username'=>'joshfrench','userpass'=>'password','userlevel'=>'admin'); //row $db['main'][] = array('id'=>1, 'username'=>'bob_smith','userpass'=>'psswrd','userlevel'=>'user'); //row function trim_value(&$value){ $value = strtolower(trim($value)); } function fdb_select($fields = "*", $table, $where = false, $limit = false){ global $db; $retv = $db[$table]; //LIMIT RESULTS TO FIELDS if(strrpos($fields, ",") === false){$field=array($fields);}else{$field = explode(",", $fields);}; array_walk($field, "trim_value"); $all_fields = array_keys($retv[0]); if($fields == '*'|| is_null($fields)){$field = $all_fields;}; $field = array_uintersect($all_fields, $field, "strcasecmp"); $retvi = array(); foreach($retv as $num =$row){ foreach($row as $fname =$fvalue){ $fname1 = strtolower($fname); if(in_array($fname1, $field)){ $retvi[$num][$fname]=$fvalue; }; }; }; //DONE LIMITING TO FIELDS if($where != false){ //UP TO HERE IT WORKS FINE //LIMIT TO WHERE CLAUSE $retvj = array(); foreach($retvi as $num =$row){ //IN THE ROW foreach($where as $k =$v){ //IF ROW MEETS ALL REQUIREMENTS if($row[$k] == $v){ $retvj[] = $retvi[$num]; //Keep that row }; }; }; //DONE LIMITING TO WHERE CLAUSE }; $retvi = (isset($retvj)) ? $retvj:$retvi; //SEND A FINAL ASSOCIATIVE ARRAY return $retvi; }; print_r(fdb_select("*", "main", array('id'=>"1", "username"=>"joshfrench"))); the previous code outputs this: Array ( [0] =Array ( [id] =0 [username] =joshfrench [userpass] =password [userlevel] =admin ) [1] =Array ( [id] =1 [username] =bob_smith [userpass] =psswrd [userlevel] =user ) )
Multidimensional Array Syntaxt For Preg_split Array Using Submitted Textarea
I have two textarea's called textarea1 and textarea2. What i did was use preg_split to split the textarea into seperate rows that i could use for analysis like so $array = preg_split("/[ ]?[ ]/", $_POST['textarea2'], -1,PREG_SPLIT_NO_EMPTY); $array2 = preg_split("/[ ]?[ ]/", $_POST['textarea1'], -1, PREG_SPLIT_NO_EMPTY); then i used a function created for me by a nice guy on here called get_ending($filepath) which basically stripped off of each peice of text the "http://www" from every URL i put into the textareas finishing off i wanted to create an array that would input an expression such as: echo "<a href='$array[1]' target='_blank'><img src='$array2[1]' border='0'>"; into a text area on the next page. ALL of this works, except that i dont know how to properly loop throught he array so it'll properly insert the text into the textarea on the next page. For now, all it does is place the array information in the page, rather statically, i would like to run some kind of if then statement that says "while $array has some kind of text in it, keep running this operation of echoing the following expression adding 1 to the end of the array number" I hope that makes sense Any ideas? Code:
Finding Elements Of An Array In Another Multi-dimensional Array
So I have 2 arrays: one contains userids. It may look like: user_id[0] =12, user_id[1] =30, user_id[2] =43 The other is a multi-dimensional array with fields like: user_info [0] = Array ( [user_id] =13 [user_flag] =1 [url] =http://www.example.com?index,0 ) user_info[1] =Array { Array ( [user_id] =120 [user_flag] =1 [address] =1234 Main St, Anytown, USA [url] =http://www.yahoo.com ) user_info[2] =Array { Array ( [user_id] =130 [user_flag] =1 [address] =134 Main St, Anytown, USA [url] =http://www.google.com )
Sorting An Array Problem, (array/string Manipulation)
I have a function that I found on google, that goes through a directory and spits out a directory tree in an array, with arrays inside of arrays, and more and more arrays inside of arrays, depending on how many subdirectories are there..... Here is a sample "directory tree" it spits out. My problem is wanting to be able to create a new array containing only the paths to all the subdirectories it finds from this array, so it is with array manipulation... Not all paths are located in the topmost array's values, but some directories are within other subdirectories and so forth.. I'm stumped on how exactly to sort through this array, whether recursively or not to grab all the 'paths' in the array period. Code:
Sorting Sql Results In An Array Using Things Outside The Array To Sort Them?
I'm using PHP to connect to a database full of place names, and their associated post codes, latitude and longitude on the earth. A user types his or her post code into a form, plus a distance (in miles), and the script looks for other area codes (first half of the post code) within that distance. I can do that fine, but the results are ordered alphabetically by postcode, and I want to order it by the distance. Problem here, is that the distance isn't part of the array taken from the database, it takes the latitude and longitude of the area it's on in the while loop, and calculates the distance between the user's post code and that one, but it's not part of the array, so I can't sort the array using it. How can I sort it? Can I add the calculated distances to the array, and sort it using sort()? If yes, how do I add them to the array? Here's the page, just to explain better what the script does: http://navimaker.org/ed/owain/results.php?postcode=gl15&distance=34 Mess around with the postcode and distance vars. I'd put the source on here too but I'm doing all this over SSH and can't copy & paste very easily .
Array Checking For Page Content In A Array
i am using a function which gets all the links from a page, from that i have a function that gathers the html in the page from each links..this part works great.. i then need to check and see if it has a applet, flashmovie etc tag in the page. if there is a tag like this in the page ineed to return true if there isnt i need to return false i have provided code thats shows how i gather the links echo them out and checks to see if certain html tags are in a page using a function $snoopy->fetchlinks($url); $results=$snoopy->results; $results=array_unique($results); sort($results); for($i=0;$i < $numberoflinks; $i++) { $results[$i] = preg_replace( "/(?<!")((http|ftp)+(s)?://[^<>s]+)/i", "", $results[$i] ); if ($results[$i] == '') { } else { ?> <a href="index.php?mode=2&url=<? echo $url.$results[$i];?>"><? echo $results[$i];?></a> <? $snoopy->fetchform("$url.$results[$i]"); $test=$snoopy->results; / if($test != "") { echo "problems seen<br>"; }else{ echo "no problems<br>"; } } }
Array Sorting Blues....2 Dimensional Array
I have a 2 dimensional array where one col contains a Unix style date and the other contains a filename. I read through a directory to get this info. I can load the array and print it out just fine, but I can't seem to sort it using any of the sort functions! I want to reverse sort them, since they are news stories that I want to display in the correct order by date. When I try to sort I get a "Warning: Cannot compare arrays or objects" message. I have the feeling it's something stupid on my part but can't find any good examples anywhere. Anyone have an idea about this? P.S. I know a database would solve this but sadly it's not an option for me right now...
Turn Array Into Multi-dimensional Array?
How can I take an existing array and turn it into a multi-dimensional array? I want to get a single row out of a MySQL table and have it in an array, but have along side the values the true field (column) length for each of the fields from the table. Here's my stab at it: $userDetails = mysql_fetch_array($resultID); $i = 0; while ($i < mysql_num_fields($resultID)) { $userDetails[$i][2] = mysql_field_len($resultID, $i); $i++; } And I guess the follow up question (if this is indeed possible) is will this work with a multi-row return from the DB also?
Setting Variable To Array Within Mysql_query() Array
I found your site while attempting to solve the problem of utilizing JOIN statements in a PhP mysql_query. Your timely and well-structured assistance to LemonFizz was very helpful, and enabled me to develop the query below. I have now queried multiple tables to produce an associative array of all of a particular student's data after selecting the student's unique ID from a drop-down. This required the use of JOIN statements in my query. The query section of the file is as follows:
Create Array From Members Of An Array Of Objects
I have the following situation: $list[] is an array of MyElement objects. MyElement has two members: MyElement->member1; MyElement->member2; What I want is to get the following: $newlist[] so that: $newlist[0]=$list[0]->member2; $newlist[1]=$list[1]->member2; $newlist[2]=$list[2]->member2; .... I need to do this using A SINGLE LINE OF CODE. Is it possible? How to do this? I tried with: array_walk($list,create_function('$a,$b,$result',' $result[] = $a->member2;'), &$result); but I get the following error: Warning: Call-time pass-by-reference has been deprecated - argument passed by value; If you would like to pass it by reference, modify the declaration of array_walk(). If you would like to enable call-time pass-by-reference, you can set allow_call_time_pass_reference to true in your INI file. However, future versions may not support this any longer.
Trying To Calculate An Average Array From An 2d Data Array
I'm trying to calculate an average array from an 2d data array. my problem is that my function does not generate an average array but just one value. but i do not understand why it does not work. code: ----- function calculateAverageRating($rating_matrix) { $average_rating = array(); foreach($rating_matrix as $cus_id => $ratings) { $counter = 0; $sum = 0; foreach($ratings as $pro_id => $item_rate) { $counter++; $sum += $item_rate; } echo $cus_id."->".($sum/$counter)."<br>"; $average_rating[$cus_id] = ($sum / $counter); } echo "<hr>"; echo "<table> <tr>"; foreach($average_rating as $key => $value); { echo "<td>$key::$value</td>"; } echo "</tr></table>"; return $average_rating; } wanted: input -> output 1 1 1 1 2 2 2 2 4 4 4 4 but my functions just does: input -> output 1 1 1 2 2 2 4 4 4 4
Passing Array Of Multidimensional Array To Function
How do I pass a part of a multidimensional array to a function. I have the following (in pseudo): $arrays[m][n]; // filled with values $chosen = 3; function doSomething($array) { // do something with 1D array } This fails: doSomething($arrays[$chosen]); Can someone explain to me why? And how to do this right?
Getting Array Information Out Of A Function On Into Another Array
I need to find a way to transfer all the values of an array inside a function out of the fuction into another array. IE function splice($filename){ if(file_exists($filename)){ $value=array("0"); // clear the array. $rows=file($filename); // break text file into a rows array for($num=0;$num < count($rows); ++$num){ $column=split(";",$rows[$num]); $value[$num]=$column;}} return $value; } $array1 = splice(file.txt) Example file data would be data1;an1;bc1 data2;an2;bc2 data3;an3;bc3
Creating An Array Of Two Elements From Another Array
I’m trying to create an array that contains a department name and a associated colour code, by filtering from a SQL result. I’ve written a simple script, but to be honest I’m now stumped how to create such an array. PHP Code:
Set An Array Of Array, Do An Unset And Display Both
see this code, i only set an array of array, then i copy this array in another one, do an unset and display both: $a["row1"]=array("row1.1"=>"row1.1.1" , "row1.2"=>"row1.2.1"); $a["row2"] = array("row2.1"=>"row2.1.1", "row2.2"=>"row2.2.1"); print_r($a); $temp=$a; unset ($temp["row2"]["row2.1"]); print_r($temp); print_r($a); it works as expected, the unset within $temp does not affect rows within $a. BUT, if you replace $a=>$_SESSION, the unset within $temp do the same thing within $_SESSION!! The row is unset within $temp AND $_SESSION!! How do you explain that?
How To Reference An Array In Multidimensional Array?
How do I reference an array within an array? $mapped_array = array_map(null, $data_array, $counter_array); // okay, so now I have an array of 2 arrays - but how do I reference each array? // the next two lines fail to give an accurate count echo "Starting with ".count($mapped_array[0])." elements in data_array<br>"; echo "Starting with ".count($mapped_array[1])." elements in counter_array<br><br>"; // now I want to start at the bottom and look for an IP in each line of data_array // which I assume is mapped_array[0] for ( $i=count($mapped_array[0]); $i > 0; $i-- ) { $data_line = $mapped_array[0][$i]; $data = explode("|", $data_line); if( in_array($ip, $data) ) { // if there's a match, element[$i] of both arrays needs to be spliced out array_splice($mapped_array,$i,1); } } // again, these next two lines fail to return an accurate count echo "Ending with ".count($mapped_array[0])." elements in data_array<br>"; echo "Ending with ".count($mapped_array[1])." elements in counter_array<br><br>"; Is there something about array_map that prevents me from referencing the arrays within the array?
Remove Array Elements With The Given Value From Array
If I have an array, $myarray, with the elements values like (1, 2, 3, 6, 8, 10). I need a function applies to this $myarray to get rid of the element with certain value such as array_function_i_am_looking_for($myarray, 3) will return $myarray with the values (1, 2, 6, 8, 10). I checked out the array function manual. The closest one is array_filter. And I just need to write a function to compare the value for array_filter.
"Array To String Conversion" Error When Constructing A Multi-dimensional Array
I'm a bit stumped as I am getting a "Notice: Array to String Conversion" error when trying to do something that on the surface should be a very simple task - create an array, and write a set of values to them based on data submitted from POST Fields. Code below: $_SESSION["increment"] = array(); $x = 0 // Counter - This will be incremented $_SESSION["increment"][$x] = array("increment_bond" => $_POST["increment_bond"], "increment_amount" = $_POST["increment_amount"], "increment_comm_date1" = $_POST["increment_comm_date1"], "increment_comm_date2" =$_POST["increment_comm_date2"], "increment_comm_date3" = $_POST["increment_comm_date3"]); It keeps throwing out that error, and does not write any of the POST Values to the array (the POST values are definitely getting sent, so that is not the problem). If I dump out the value of $_SESSION["increment"], I get "1A" ?!? I'm sure that there is a pretty simple mistake lurking somewhere - I just can't seem to figure it out.
Putting An Array Within An Array?
Still having fun trying to build the perfect form and validation classes and wondered if anyone can help on the following. In the following function, how can I make $validationparameters an array so it can accept multiple values that I can iterate through? Don't need the iteration part (yet). function setField($type, $name, $value, $style, $label, $validationparameter) { $this->number_of_fields++; $this->fields[] = array('type'=>$type, 'name'=>$name, 'value'=>$value, 'style'=>$style, 'label'=>$label, 'validationparameters'=>$validationparameters); } This is part written function that I will use to pass the multiple values to the array. function setValidationParameters($number, $parameter) { $this->fields[$number][validationparameter] = $parameter; } I am beginning to confuse myself and wondering if anyone can add some sanity to what I am doing.
Combine Array Of Array
$array1 = array( array( "product_id" =3, "SKU" ="AES46", "qty" =3, ), ); $array2 = array( array( "product_id" =3, "SKU" ="AES46", "qty" =2, ), array( "product_id" =4, "SKU" ="AES47", "qty" =3, ), ); I want to add up the qty of two array if the product_id is same I try on $array1 + $array2, but which is not I want, I only have to use 2 foreach loop in my mind foreach ($array1 ...) foreach ($array2 ...) if ( id same ) Have other better suggestion or PHP function for this ? I am using PHP 4.4
Getting An Array Out Of A Superglobal Array
I have an array called $trackarray[] each index contains a number and i need to loop through this array and access each member to get the number. for example Code: $no_of_tracks = $_POST[$trackarray[$y]]; echo $no_of_tracks; for ($x=1; $x<=no_of_tracks; $x++){ .... do stuff....} $y above is the index number of the track array i need to access so would be 0, 1, 2 etc but because its been put in the POST array i dont know the syntax to get it back out I either get an error about " and ' marks or it returns nothing. Any ideas?
Array Inside Array
I have got an array. In this array, there are multiple arrays. I want to show some of the info in one of the arrays which are inside the main-array. It's like this: $array = Array( [test] => Test, [lala] => Array(with content in it)....); I thought I just could say "print $array[lala][0];", and it would give me the first value of "lala" in the $array. This does not work, so how can I do it then?
JS Array - Using PHP To Populate JS Array
I have a page where two select boxes containing lists of people ( Left is Absent and Right is Present) driven by several arrays, such as absent_Member, absent_Visitor, and present_Member, present_Visitor. This is so that an additional select box can be used to choose which category you want the select box to display. You can click on people on either side and click a button to swap them across. That is the easy part. The part I am stumped on is my familiarity with JS arrays. I am used to the ease of PHP for searching for values within arrays, such as in_array(needle, haystack); When I swap from on box to another, the only values being passed are options.value ( this equals the persons database ID # ) and options.text ( this equals the persons Last, First name ). The best way I can think to search the arrays to find which one this person resides in is a pathetically taxing way, such as Code:
Sorting An Array With Another Array
I have an array that is an order of things: array(23,54,1,45,12,9) And then I have an array of values from the table. Within this array is an id which relates to the previous array. It holds quite alot of information so I'm hoping there might be an easy way, as opposed to the long and messy way, to sort this array with the values in the other array. Looking through the array functions, I can't quite see it. Any advice on this one?
No Array Entry Vs Null Array Entry
Consider this statement related to Fields sent to PHP via an HTTP POST. $A = $_POST["FieldName"]; If the page did not have a form field with FiledName, the result is that $A is empty. If the page DID have a form field with FieldName, but the field was left empty, then $A is empty also. How should I test $_POST to distinguish between these two conditions.
2D Array
What i want is something like for ($i=0;$i<$var;$i++) { create 2D array if (condition) { push element in array // } } ie..1=>a,b,c,d 2=>e,f,g etc then i want to count the size of each array element eg. for array1 : no of elements 4 for array2 : no of elements 3 etc Not done 2D arrays before.
Array Help
Is it possible to do what I want to do with the $no_read_extentions array? instead of repeating the code with each extention in preg_match.
Array Of An Array
I have a problem. I have a text file that looks like this: usernameassword otherusernametherpassword I broke up each line into an array using explode, so now my array[0] is "usernameassword and array[1] is "otherusernametherpassword". I want to break up each array into 2 separate arrays. For example: farray[0] = "username" farray[1] = "password" sarray[0] = "otherusername" sarray[1] = "otherpassword" How can I do that?
Db Or Array
I don't know if I should store details like meat eater, veggie etc etc in a db and call it into a drop down menu or create a function with an array of different options i.e. #1 can relate to "meat eater" #2 can be "veggie" Thing is I'm trying to make as less possible connections to the db as possible as it slows down the server.
|