Tracking Forums, Newsgroups, Maling Lists
Home Scripts Tutorials Tracker Forums
 
  HOME    TRACKER    PHP




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 Complete Forum Thread with Replies

See Related Forum Messages: Follow the Links Below to View Complete Thread
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');

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.

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.

Delete Item From Array
How do I search for an item within an array, then delete it?

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;

Delete An Item From An Index Array?
How can I delete an Item from an index array in php4?

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

How To Walk Array And Delete Matched Elements?
I'm kind of lost on this one - I need to modify 2 files based on user input:

How To Clear A .txt File With Php
I'm busy making a very basic and simple content management system wich
stores the text in a .txt file. now i need to know how i can clear the
..txt file.. now it just adds the new text to the .txt file while it
should replace it!

Can't Clear SESSION
Have a login that once that username and password are authenticated, user is redirected to the appropriate page depending on their area of expertise. If I try to login several different people on my computer over a period of a few minutes each is authenticated appropriately but they are ALL redirected to the page that corresponded to the first person I logged in. PHP Code:

How To Clear Cache
I have a php file which will list the pending
task for each developer. If the developer
changes some thing it will update to database.
Once the user clicks the update button it shows
the another page and there will be button back to
list of pending task. It will again fetch from database.

At the second time if user update some other data. It giving
me the old data list also.

I used ClearStatCache() this is not working. And also I added

<META HTTP-EQUIV="Pragma" CONTENT="no-cache">
<META HTTP-EQUIV="expires" CONTENT="0"> in my php file.

Clear Screen
After a echo statement I close a php script and begin a html code. Before the upload of html code I would like to clear the screen.How can do it?

How To Unset (clear) A Var?
Code:
$DatabaseActions = new Database();
// some code
$DatabaseActions="";

What is that the best way to unset it (i doubt it) I want it to be NULL - "dissapear"

Clear Screen
I'm using PHP on my Linux box on the command line.

It need to clear the screen, as I would do with the 'clear' command on
the bash. Is there something equivalent in PHP available?

Clear Memory
I'm having a strange problem in a script I wrote. Some variables that begin as input names, maintain their value for a long time after they have been initially used.

Basically what happens is something is input in one form under the name "title", and when I have a field with the same name in another form, the new field uses the value of the old one. This is really annoying and I was wondering if anyone could explain this.

Clear Cache
Is it possible to clear the notebook or cache on a visitors PC with php??

I am trying to stop people copying the txt from a site by either selecting the txt and copying to clipboard or taking a screen shot.

I have been told that this is possible with PHP but am yet to find anything in the manual!! all I can find is informatin about clearing the server cache.

Sticky Variables (can't Clear)...
I've set up a couple of polls on a web site with radio buttoned choices.

I pass the decision that the voter has chosen from the HTTP_POST_VARS into a session var to enable easy access by several subsequent functions.

If the vote is valid (if a decision has been chosen before clicking the 'submit' button), it is saved and a bar chart of vote results is redrawn.

After these steps, the session variable and the HTTP_POST_VARS array are unset. I also define the page such that it doesn't cache. I do these things so that the voter can't re-vote by re-loading the page.

I've confirmed that both the form variable and session variable have been unset, but somehow the variable comes back into memory upon page re-load. Instead, an error message should be displayed stating that a choice hasn't been selected - since the data should have been cleared.

Is the old variable data being recalled from browser memory cache? I guess there's no way to force that to zero. Where else can form variables be recalled from besides the HTTP_POST_VARS array.

Mysql Clear Row Command?
is there a mysql function that will just zero out (but not delete) all column values for a given row? so the desired query would look something like this:

update table
set
*=''
where id=$id

How Do I Clear/unset All Variables?
I know you can use unset but I want something that can clear vall of the variables from memory rather than having to specify which ones to unset.

Function To Clear Screen?
Once a user clicks submit on a form, I would like to clear the screen and display the results of the form.

Automatically Clear A Table
Is it possible to have a table automatically clear its contents at a set time everyday?

Clear Form After Submit
i have a form that i want cleared after user submits the form.  right now as it stands if the user hits the "BACK" button on the browser they are still able to see what they typed. Code:

Cron To Clear A Folder
I'd like to create a cron to empty a folder of temporary images and just wondered how to go about doing it. I'm happy with how to work the cron tab... but do i just write a script and point the cron to it?

What would the script look like to clear a folder of ALL files? Do I need to think about security issues too?

How To Clear POST Data?
I've looked everywhere and cannot find my answer. After a successful form submission it tells the admin it was successful but then I want the form to clear out. Because I do have it where the data is redisplayed in the form just in case of an error. But when there isn't an error and the form is processed it still shows the POST data ... anyway to clear this out?

Clear GET & POST Value On Refresh Page
Hi everyone.

when I fill a form and then submit it , it works right
[address?value=sth]

But I wanna if then form refreshed by user, address changes to
[address] without POST & GET.

What's User Credentials Are Sent In Clear Text
the Acunetix Web Vulnerability Scanner said my php scripts has the problems of "User credentials are sent in clear text", but my scripts never output any information about User credentials, does anyone know how to fix those problems ?

Session Causing My Field To Clear!
i have a registration form that receives user's input like firstname,lastname..etc. and of course a validation. the problem is when a user mistakenly inputs a wrong validation and tries to submit it the error message and the fields are cleared, and i think it's wrong it should still display the user's input. here is my code:

Clear Cache/temp Data/buffer
im using a form in a php page. it it submits and process the data to itself (the code on top of the page). after the data is processed succesfully (for example, adding new items to a database), how can i clear all variables? i tried setting them all to NULL in the top code , but they are still there.

whenever i refresh the page in my browser, it still adds (the last command used) another item (the same item dadded previously). is it a probelm in the coding? or the browser is the one to blame?

PhpBB2 - Clear Text Password In Config.php
Is there a way to avoid having the DB password (and/or ID for that matter)
clear in config.php?

PHP Needs To Clear Memory After Making Mysql Functions?
I use $result=mysql_fetch_array(...), I need to clear memory there or it happens automatically?

Connecting To MySQL Without Storing Password In Clear Text
I have a website in a Linux/Apache shared hosting environment and have
been given access to the MySQL server running on the same machine. To
access this database from PHP, I have to call mysql_connect(host,
user, password) where the password is hardcoded into my PHP source
file in clear text.

I see two security problems with this:

1) Since the PHP source is in my public webserver area, another user
of the same server could telnet into the server and look at the source
file and see the password file. I can't lock the file down using Unix
file system permissions or else the webserver won't be able to read
it.

2) If my ISP messes up their webserver config and accidentally stops
parsing PHP files and outputs the PHP file as plain text, the password
will be visible to all.

Is there any other way for PHP to authenticate itself to MySQL?

Error Message Causing Form Inputs To Clear
My problem is this: I built a simple form that connects to a sql database and inputs the information. I made it so it puts the error message at the top of the page, when the user leaves a required field blank, password is too short and so on. The problem is that it clears all the fields when it displays these error messages.

Is there a way to prevent this so it doesn't all have to be entered again. Am I just going about this the totally wrong way? I really haven't been working with php that long, about a week really, so excuse me if this is a total noob question. Code:

Delete From $var
Is it not possilbe to have a variable for the table name in a delete statement (mysql database). inside an if this button is hit statement I have:

$sql = "delete from $type where id_num='$number'";
mysql_query($sql);
echo "$sql";

when it echos $sql it doesnt have the $type var where the table name should be, it just leaves that blank.

Delete A Row
This should be simple enough but for some reason it's not working. The $name is a number which is being posted across when the user clicks submit. I want the PHP to then access the Database with this number and use it to delete the staff ID (which is a PK).

With this code I get the error:

Warning: ociparse(): supplied argument is not a valid OCI8-Connection resource in /homedir/ilex-s01/jmsuther/public_html/DeleteStaff.php on line 16

Warning: ociexecute(): supplied argument is not a valid OCI8-Statement resource in /homedir/ilex-s01/jmsuther/public_html/DeleteStaff.php on line 17
;

The code is:

$name = $_POST["staffnodelete"];
IF ($staffnodelete=="" )
{print "You selected $name - for deletion ";}

putenv("TNS_ADMIN=/u1/oracle/Products/shu10g/network/admin");
$con = OCILogon("username","password","10g");

$query = "DELETE FROM staff WHERE staffno = $name";
$query = $query_post [$name];
$stmt = ociparse($conn, $query);
ociexecute ($stmt);

How To Delete Fields
I would delete with php, all record of a table mysql where the seven left chars of the field is equal to the data in input($seven_chars).

I have used the the belowe istrucrion but it do not work.how can I do?

mysql_query ("DELETE FROM my_table WHERE substr(myfield,0,7)=$seven_chars");

Delete A Line In PHP
What i want to do is to open a file read the file Select a particular line from the file and delete that line and close the file. How to do it in PHP.

Can't Delete Cookie
Right I am quite new to php but have managed to create a simple log in/log out thing with cookies. All was working fine and as expected until I added a new section of the site. The new section stores another cookie (latest message user has read) so that next time they visit the site it will highlight the 'new' messages.
However since adding this I can no longer log out.

Can't Delete Cookie, Help Please~
Page1: <? setcookie("book_id", $book_id ); ?>

Page2: <? setcookie ("book_id", $book_id, time() - 3600); ?>

Can't delete cookie at once but reload page 2 two times
how to delete $book_id cookie without reload?

Cookie Won't Delete
I'm trying to setup a simple user authenication for my site. I'm using cookies to pass the credentials between pages. But the function header() is giving me problems logging in and logging out. As you can see in the code below, I try to redirect the user to a page after setting or deleting the cookies. The scripts redirect okay, but the user never logs in and never logs out correctly. The scripts works correctly (logging in & logging out) only if I comment out the header() function.

Here's my code for setting the cookie (login.php):

Delete File
I want to delete a file that is located on a server. The filename is in a Mysql database and now I have to put the line 'system("del c:apachehtdocsshopimg.gif");' somewhere in my code underneath. Any Idea how ? This line works already, but now the '.GIF' has to become a $file that equals the filename from the database...

Delete All Replicated Except One
I ran PHP codes that creating tables and inserting records to tables., But something happened, someone of them is inserted more than once.

aa1345 | Ninsonoto
aa1345 | Ninsonoto
aa1348 | Ayumi Tohina
aa1348 | Ayumi Tohina
aa1348 | Ayumi Tohina

There are thousands of records there. So I think i have to write a script that able to delete all the replicated except one..
e.g : Delete four of aa1348 records.

Delete New Lines
I would like to delete the new lines, I mean the, so Itried this:
str_replace($row['facts_conten t'], &quot;
&quot;, &quot;&quot;) ;
But the new lines are still there, how can I do?

Can't Delete From Table!
I'm not to familiar to php and sql. I have this assignment to read from database in a table and I HAVE TO be able to push a button causing one costumer to vanish. something to do with id = $id... can anyone help me... and help me fast!

This is my code:

What Is The Best Way To Delete File ...?
I have script that allows a user to upload a txt file for processing, filtering, to save bandwidth,instead of user reuploading the file everytime he/she does a new process on the same file, i save the file to the server, and process from that file. What I want to be able to do is, when the user uploads a new file, or leaves the site, this temp file is automatically deleted (saves disk space).

Delete From Many Tables
I am trying to delete rows from a mySQL DB that consists of multiple tables. I am trying to use a function PHP Code:

Delete Records
I`m just trying to figure out the best method to delete my records and wondered if it was possible to do a DELETE statement to remove any records that don`t match. Here is my code so far:

$Query="select blah its huge:-)";
$RESULT=mysql_query($Query);
$my_rows=mysql_num_rows($RESULT);

for ($a=0; $a<$my_rows; $a++){
mysql_data_seek($RESULT, $a);
$Array = mysql_fetch_array($RESULT);
printf("%s<BR>", $Array['Email']);}

My Query returns Matched Records, what I would like to achieve is deletion of the records that didn`t match, would it be possible to do that under the printf statement. So delete all the records in the table that don`t match up to $Array['Email']??

SQL Insert And Delete?
Anyone know if there's a way to call a query but remove whatever you grabbed from the database, or would I have to do a query to retrieve what i needed, then follow it up with a delete on the same query results?

Delete An Object ?
I use OOP with PHP4 and i don't understand something.

I have 2 classes VISIT & PLANNING like that:

class clVISIT {
var $when;
var $where;

//constructor
function clVISIT($_when,$_where) {
$this->when = $_when;
$this->where = $_where;
}
}

class clPLANNING {
var $who;
var $visit = array();

//constructor
function ClPLANNING($_who) {
$this->who = $_who;
for ($i=0;$i<10;$i++) { $visit = new clVISIT("foo".$i , "foobar".$i ) ; }
}

}

Ok, in the last constructor, we can see that i create new clVISIT
object. My question is: how can i delete some of them in the same
constructor ? is there a word like "new" but to delete ?

Delete Script
PHP and MySQL and I'm having some problems getting
this script to work. I can't get this to work and I don't understand
why. I don't get an error or anything, it almost seems like the page
refreshes. I went to the phpmyadmin and the row is still in the
database. The $_GET parts work perfectly in another script and the SQL
statement works when I insert hard values in it. Any thoughts would be
greatly appreciated. Thanks in advance.

<form method="POST" action="<?php print $_SERVER['PHP_SELF']; ?>">
<table>

<tr><td colspan="2" align="center">Yes <?php
input_radiocheck('radio','yes_no', $defaults, 'yes'); ?No <?php
input_radiocheck('radio','yes_no', $defaults, 'no'); ?>
</td></tr>

<tr><td colspan="2" align="center"><?php input_submit('save','Add'); ?>
</td></tr>

</table>
<input type="hidden" name="_submit_check" value="1"/>
</form>

<?php

function process_form() {

// Access the global variable $db inside this function
global $db;

$isbn = $_GET['isbn'];
$artist_name = $_GET['artist_name'];
$album_title = $_GET['album_title'];

if ($_POST['yes_no'] == 'yes') {

$delete_sql = "DELETE FROM lounge WHERE isbn = $isbn AND artist_name =
'$artist_name' AND album_title = '$album_title'";
// Delete the record
$db->query($delete_sql);
print "The record was deleted";
} else {
print "The record was not deleted";
}
}

?>


Copyright © 2005-08 www.BigResource.com, All rights reserved