Completely Delete A Specific Array Index
I was wondering if anyone could tell me if there is a way to completely delete a specific array index once it has been set. For instance, I have an array with 50 indexes (0 - 49) sizeof = 50. Now, I want to eliminate 10 indexes, making my array sizeof 40 and having array indexes 0-39.
View Complete Forum Thread with Replies
Related Forum Messages:
How To Clear An Array Completely?
I have an array variable that I use over and over. Can I clear it by just doing the following? $myarray = array(); If the previous array has more elements than the current one, will it still have the old data at the end? I want to prevent this problem and I don't want to do a loop for efficiency consideration.
View Replies !
Delete A Specific Row
How can i delete a specific row from a mySQL table. I want to delete Image2 (or make the value of it is nothing, NULL) <?php $con = mysql_connect("localhost","name","password"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("npsari_other", $con); mysql_query("DELETE Image2 FROM ads WHERE ID='$ID'"); mysql_close($con); ?> Is this code right, because it doesnt work.
View Replies !
Delete Specific Entry
I'm working on a CPanel on my website that gives me the posibility to edit both the blog, news and shoutbox. So far I'm done with adding new: news, shout & blog. But I'm stuck when it comes to deleting. Like if someone is spamming my shoutbox I want to be able to log in and delete the spam shout. I wish I had some code to show you for the delete part, but I dont even know where to start.
View Replies !
Delete Specific Records
On clients machine, currently to delete on trainee record it runs 10 queries to delete records from 10 tables. At the time of running all queries, server shows (104) Connection reset by peer. An error condition occurred while reading data from the network. I think it because of running 10 queries at a same time. Is there any possibility that through one line of query we can delete record from 10 tables. I've tried following query DELETE FROM table1, table2, table3, table4, table5, table6, table7, table8, table9, table10 WHERE empID = 11; But it gives ' error in query.
View Replies !
Delete Specific Texts From File
The text file is in variable length. We can't point to where to delete. But there are texts we want to delete in the text. How can I do ? The only way I can think of is load entire file, match the text we want, replace the text, and then rewrite the file. Is this way correct ?
View Replies !
How To Add An SPECIFIC Array
sorry if the subject isint really good to understand, now i will try to explain my best. I recently installed a hack in phpbb and that particular hack allows only 1 variable, but i want to add more than one, and i thought the best thing to do it is in an ARRAY, but i dont know how to do it in an array, the code looks something like this:
View Replies !
Find A Specific Value In An Array
What I want to do is compare a value against an array and perform a specified action if the value is in the array. Specifically, I want to preselect an option in a list based on whether or not the option id is in a field (a 'set' column) of a specific entry in a db. My code so far is: PHP Code:
View Replies !
Finding Specific Array Key
I have an array with sub arrays, example: $an_array = array([0] => ([id] => 152 [otherstuff] => blah... ) ([1] => ([id] => 167 [otherstuff] => yadda... ) ([2] => ([id] => 17 [otherstuff] => stuff... ); I have a variable that stores an id, how can I get the key of the specific array, ie: $x = 0; $var = 152; if($an_array['id'] == $var){ $x = get_this_array_key; } I don't know how to get the key of the array where I have the 'id' value of that array.
View Replies !
Index Of Array
I uses the function in_array to find out if a specified word appears in a specified array, if it is there I want to get the index of this word in the array. So I can use this index to set a value in array2, at the same index. Jeg bruker in_array for å sjekke om et bestemt ord finnes i en bestemt array, hvis det finnes vil jeg få hentet ut indeksen dette ordet har i array'en. Så vil jeg legge inn et tall i en annen array på samme index som ordet. if (in_array($word, $array1)) { $i = index_of_word($array); $array2[$i] = $number_to_put_in_same_index_as_the_word_in_array1; }
View Replies !
Need Help Extracting Specific Records In An Array
I am using a pc of code that is as follows: while ($row = mysql_fetch_array ($result)) { echo "user_id: ".$row["file_name"]."<br>"; echo "user_id: ".$row["file_author"]."<br>"; echo "fullname: ".$row["file_keywords"]."<br>"; echo "fullname: ".$row["file_description"]."<p>"; } This will extract all the data from the records that have been stored in $row. The question I have is how to take out slective informtion? Let's say I have a complete $row array (40 finds) but only want to show the first 3-6 records. How do I access hose specific miages?
View Replies !
Sort By Specific Array Addresses
I have a file containing lines of information about files. Each piece of information is separated by a "|" character. I want to extract the information and then sort it based on some of the information (for example it contains the filename as the second piece of information) PHP Code: $array = file("files.txt"); foreach ($array as $line) { $info = explode('|', $line); //filename is in $info[1] $order[] = $info[0].",".$info[1].",".$info[4].",".$info[5].",".$info[6].",".$info[8]; } I have no idea where to start or which sort function to use. I will be needing to sort by specific array addresses. I'll need to sort $order according to $info[1] values or $info[8] values.
View Replies !
Accessing Specific Array Values
I'm struggling with performing some calculations on array values. What I'm trying to do is get some values from an array that holds shopping cart details than add them together but only for certain items. Say I have an array that has 4 entries: [0]([product_id] => 100 [quantity] =>1) [1]([product_id] => 104 [quantity] =>3) [2]([product_id] => 117 [quantity] =>4) [3]([product_id] => 100 [quantity] =>2) and a variable that holds a pre-determined value: $prod_id = 100; I want to get all the quantities where the product id is equal to the variable value, so in this case it would be 1 and 2, then i want to total these values so 1+2=3.
View Replies !
Renumber Array Index
Is it possible that I can renumber array indexes? The problem is that I am using array_unique, but it is returning something like this: [1]->value1,[3]->value2,[5]->value3 How can I reset the numbering, so the indexes are 1,2,3 (using a function would be preferable).
View Replies !
Sort Array Without Index
I'd like to sort a multidimensional array that hasn't numerical index, in fact it is like: Array ( [mobile] => Array ( [name_str] => mobile [relationCount_int] => 1 ) [video] => Array ( [name_str] => video [relationCount_int] => 2 ) [flash] => Array ( [name_str] => flash [relationCount_int] => 1 ) [tool] => Array ( [name_str] => tool [relationCount_int] => 1 ) ) And I'd like to sort, for instance for the value of "relationCount_int", so the new order should be something like: Array ( [video] => Array ( [name_str] => video [relationCount_int] => 2 ) [mobile] => Array ( [name_str] => mobile [relationCount_int] => 1 ) [flash] => Array ( [name_str] => flash [relationCount_int] => 1 ) [tool] => Array ( [name_str] => tool [relationCount_int] => 1 ) )
View Replies !
Array Index Question
I have source information in a file, and (part of) this information comes as coordinates. A coordinate consists of a letter followed by a number, ranging from a1 to i9 I'd like to count the number of occurrences of each coordinate, and put them in a matrix. The matrix should look like this (metasyntax): matrix = array ['a'..'i'][1..9] Later on in the script I'd like to be able to refer to a cell in the matrix by using the same letter/number combo. I know I can define an array using strings as keys, but how can I define a..i as keys without the need to specify them all individually?
View Replies !
Quotes Around Array Index?
I have a question about quoting array indices. This is from Rasmus Lerdorf's Programming PHP: Quote: You don't have to quote single-word strings. For instance, $age['Fred'] is the same as $age[Fred]. However, it's considered good PHP style to always use quotes, because quoteless keys are indistinguishable from constants. When you use a constant as an unquoted index, PHP uses the value of the constant as the index: Code:
View Replies !
Printing An Array Using An Index?
I have to print an ACH file from an array I will recieve. I recieve this array through a function then I have to print this array to a file called "ACH.txt". The ACH file is broken down like this. position 01-017 is 1st record to be printed position 018-30 is 2nd record to be printed position 31-44 is 3rd record to be printed etc. I was thinking psuedo code like this Code:
View Replies !
Array Index Problem
im building a shopping cart, and im having the following problem. the array in the bottom is the way i store customer's product and quantity. For example, refer to below, product 3's quantity is 2. $item['product1'] = 1; $item['product2'] = 4; $item['product3'] = 2; $item['product4'] = 1; the problem im having is, how am i suppose to display the product? is it any function to list out the array index? i tried print_r, it did list out, but, it isnt the thing i want... i want an output like the following so that i can use the product id to retrieve the product information from database... product1 : 1 product2 : 4 product3 : 2 product4 : 1
View Replies !
3d Array Index Not Found
Why doesn't this work? PHP Code: $i = 3; foreach($contact as $key => $val) { if($val['name'] == 'tom'){ echo $val['name']; // Tom echo $val['email'][$i] //DOESN"T PRINT tom@foo3.bar echo $val['email'][4]; //tom4@foo.bar ...
View Replies !
Undefined Index In Array
BACKGROUND: Create data arrays for graph plots WHAT WORKS: The SQL portion, the creation of master array-> from which I chose data array per unique category: Code:
View Replies !
Accessing The Last Index Of An Array
for example, i have the following array: $p = "hello.html.c"; $p1 = explode('.', $p); now, if i want to access the extension (c, or index 2 in this case), i would have to do $p1[sizeof($p1) - 1]. I'm used to in python's list just doing p[-1] to accessing elements from the back. I was wondering if there is a similarly easy way of doing this in php.
View Replies !
How Can I Swap An Array Index?
lets say I have an array like this... $Array[0] = "Apples" $Array[1] = "Oranges" $Array[2] = "Grapes" $Array[3] = "Pears" What I want to do is swap the index of "0" with the index of "2" so that my array will look like this. $Array[0] = "Grapes" $Array[1] = "Oranges" $Array[2] = "Apples" $Array[3] = "Pears" *The changes are noted in BOLD* How can I do this?
View Replies !
Summing Specific Values In A Cookie Array
I am building a simple shopping cart and I am having problems trying to add the costs of the items to generate a total cost. I am new at this so forgive me if my technical verbiage isn’t the greatest! I am trying to sum specific values in my arrays (or the price portions of the arrays). I have tried every imaginable way with the array_sum command and nothing has worked for me! Here is what my cookie information looks like after I put 2 test items into the cart that cost 18.00 each. Code:
View Replies !
Recursively Searching Array For Specific String
Simply put, I'd like to find a string such as �' in an array. The string is not strictly �', but would be 508429_501_21.jpg, 508429_601_18.jpg, etc. - multiple occurences are possible. I found a great function that recursively scans through a directory structure; I've attached it here, and it results in the following output. Code:
View Replies !
Find Current Index Value In Array
I am looking for a way to find the numerical index of an array item without coding in a manual count using a foreach. Here is the situation: I am throwing a class a configuration array, where all of the arrays will have the same number of items as follows: PHP Code:
View Replies !
Back Referencing To Get An Array Index?
My website needs to allow users to specify where a thumbnail image will appear in the text ($articleText) they submit. The thumbnail filenames are held in a single-dimensional array called $photos e.g. the users are to type [thumb4] to specify they want thumbnail four ( from array position 4 ) I was hoping the following expression would work, but it doesn't. The returned text always includes <img src="thumbs/"> i.e. no image filename is inserted. (I was expecting something like <img src="thumbs/dave.jpg"> ) $articleText = preg_replace("/[thumb(d+)]/", "<img src="thumbs/".$photos[$1]."">", $articleText);
View Replies !
Undefined Array Index Question
I am curious about how php deals with the following situation where I use an undefined index into an array. PHP seems to be behaving exactly how I want it to but I want to make sure that it is not a fluke. It seems like most programming languages would crash if you used an undefined index. Why does PHP work the way it does? My example is below ....
View Replies !
Retrieve The Index Number Of The Element Of An Array
After some looking around - and maybe entering just the wrong keywords in Google :) - a short question: is it possible to retrieve the index number of the element of an array, let say that there is an array $myArray = ("John", "Tom", "Dick","Harry","Peter") I am looking for a function that tells me that Harry is the fourth element. (I have tried in google things like "retrieve index array php" but without result)
View Replies !
Accessing Numerical Array Index In Foreach
I have no trouble looping through an array using foreach. To keep track of the index, I set a variable before the loop and increment it in the loop: $index = 0; foreach ($array as $item) { blah; $index++; do something that requires knowing the index of the current item; } Is there a better way to access that index value?
View Replies !
Getting A (non-radio) Button's Index Number From Array
If you could assist me with the following situation, I have a table of data retrieved from database displayed on screen. To each row of data, I have added action buttons, such as "Edit", "Add", and "Comment". Since I do not know how many rows of data will be retrieved - and therefore how many buttons I need - I am using button arrays for each button, like so: echo "<input type="submit" value="Comment" name="Comment[]" />"; In the php file that processes the input from this form, I have the following code, which I was under the impression would give me the index in the Comment array of the button that was fired. if (isset($_POST['CommentMedicalHistory'])) { $indexOfComment = each($_POST['CommentMedicalHistory']); echo "index = {$indexOfComment['key']}"; } Unfortunately, it is returning 0 as the index all the time, even when I do not click on the Comment button in the first row. Do you know by any chance how I could get the correct index of the button that was pressed from the array?
View Replies !
Structure The Data In Column That Should Be Index Of Array
MySQL Table structure. ID name value 1 c01 abc 2 c01 def 3 c02 xyz Here i want to structure the data in such a way that name column should be index of array and values should be mapped to index for eg. Array( [1] => Array ( [c01] => array([0] => abc [1] => def [2] => Array ( [c02] => array([0] => xyz .
View Replies !
Delete From Array
let's say I have an array $letters(a,b,c,d,e,f) is there a function that will remove 'd' from the middle. I'm looking for something like array_delete($letters,'d');
View Replies !
Delete From An Array
If I have an array like: $myArray = array('Firstly' => Ƈ', 'Secondly' => ƈ.0', 'Thirdly' => 'three'); How do I delete a specific key and it's corresponding value? I know you can array_shift and array_pop ... but I want to be able to say. Array_Remove($myArray, 'Secondly'); ... or something like that how do I do it?
View Replies !
Delete/drop Value From An Array
Hi, I have an array of values that I am matching against a string and I want to drop the value from the array if it is in the string. My array looks like: 0=>val1, 1=>val2, etc I understand how to check to see if the value is in the array, but not how do get rid of it if it is.
View Replies !
Delete Array Element
How can i delete an element from one array. Let us suppose that i've an array of 10 elements $a[0], $a[1], $a[2]...etc And when i delete $a[2] i wanna the elements to be re-ordered like this $a[0] will be the same $a[0] $a[1] will be the same $a[1] but $a[2] will be the $a[3] element i had before deleting $a[2] It would be called in Delphi, HOW TO DELETE AN ELEMENT FROM A COLLECTION? Is this possible? Have i to use another type of data? Hope you've understood the idea.
View Replies !
How To Clear/delete An Array?
I am using an array in a loop, and every time I loop I need to have the array be empty. I cannot find an array function to empty the array, or clear it. Have I missed something somewhere ( I suspect I have) ?
View Replies !
How Do I Delete Items From Array?
I can add several items to the basket, but how do I delete one from the basket? I want to delete any of the added items. Here is my code for creating the array and adding items to it. // creating the array $item = array(); $item['id'] = "1"; $item['price'] = "100"; $item['quantity'] = "1"; // add item $_SESSION['basket'][] = $item;
View Replies !
Simple Delete From Array?
Any way to do a simple delete from array? In other words, what would be the *easiest* (and fastest php runtime) way to delete "banana" from the following array: $my_array = array( "apple", "banana", "grape", "lime" ); .....so that $my_array will now be: $my_array = array( "apple", "grape", "lime" );
View Replies !
Delete Element Of Array
I am trying to check if any of the elements in a certain array (which is to be inserted into a mysql table) are already listed in the table. For example I have an array containing multiple URL's, and I want to check whether any of these urls is already in my table. If it is i need to remove that particular element of the array. Can anyone point me in the right direction, i am currently trying array_search and in_array.
View Replies !
Delete File (array Setup)
I have this code that i use in a different site that deletes one file(photo). how can i build an array to delete three files photo1, photo2, photo3,. <?php $myFile = "../images/news/". $_POST['photo']; if (!empty($_POST['photo']))      { unlink($myFile); } else      {        echo  "";      } ?>
View Replies !
Safe To Delete Elements Of Array In Foreach
Is it safe to remove elements from an array that foreach is working on? (normally this is not the case but not sure in php) If so is there an efficient way to handle it? (I could add the indexes to a temp array and delete afterwards if necessary but since I'm actually working in a nested situation this could get a little messy. I guess I could set there values to
View Replies !
|