GIDForums  

Go Back   GIDForums > Computer Programming Forums > MySQL / PHP Forum
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 10-Jul-2006, 18:57
Philsco Philsco is offline
New Member
 
Join Date: Jul 2006
Posts: 2
Philsco is on a distinguished road
Question

Just a couple questions.


Hey, I'm brand new to PHP, but I have some C++ (slight), a lot of Flash's Actionscript, HTML, and BASIC behind me. PHP seems similar to a lot of other computer programming languages, but it's still quite a bit different.

If it's not too much trouble, I need help figuring out the PHP code to check a variable against an array from a file.
I need to check a variable against an array for any duplicates of the variable, and if there is no duplicates, I need to add the variable's value to that array as the identifier being the variable getting checked, and the value as "Level 1." Adding the variable to the array is easy enough, though. I can picture the steps I'd need to take -- grab the array from the other file, check it against the variable, filter through them, find another similar one, break the cycle, return the variable with a new value of "Taken", or if no similar files exist, add it into the array -- but I don't know the code I'd need to use.

I can put together parts of it, though. Assuming $arr is the array I grabbed from another file, and $variable is the variable I am checking against the Array.

PHP Code:

foreach ($arr as $value)
{
  if ($value == $variable){
    $variable = "In Use";
    break;
  }
}
if ($variable != "In Use"){
  $arr[$variable] = "Level 1";
} 



So, is that right, at all?
  #2  
Old 10-Jul-2006, 22:51
admin's Avatar
admin admin is offline
Administrator
 
Join Date: Sep 2002
Posts: 741
admin will become famous soon enough

Re: Just a couple questions.


Hello Philsco,

To answer your question, yes, it's right... BUT, there are other options you should / can consider. Like the in_array() function.

PHP Code:

<?php

// check if (the value of) $variable already exists inside $arr
if( !in_array($variable, $arr) )
{ // it does not, so we add it to $arr
  $arr[$variable] = "Level 1";
}

?>

__________________
Custom BB codes you can use here:
[HTML] | [C++] | [CSS] | [JAVA] | [PY] | [VB]
  #3  
Old 11-Jul-2006, 00:31
Philsco Philsco is offline
New Member
 
Join Date: Jul 2006
Posts: 2
Philsco is on a distinguished road

Re: Just a couple questions.


Oh, Hell yes. Thank you.

Now, I'm sorry to bring up further basic programming questions, but what would be the best way to post and retrieve this information? I've heard differing opinions between $_Post and $_Get, but they were both verbosely explained, and poorly, at that.
  #4  
Old 23-Aug-2006, 22:04
MrPostman MrPostman is offline
New Member
 
Join Date: Aug 2006
Posts: 5
MrPostman is on a distinguished road

Re: Just a couple questions.


Quote:
Originally Posted by Philsco
Oh, Hell yes. Thank you.

Now, I'm sorry to bring up further basic programming questions, but what would be the best way to post and retrieve this information? I've heard differing opinions between $_Post and $_Get, but they were both verbosely explained, and poorly, at that.

Post.

GET encodes data in the URL, it is insecure, can be easily manipulated and there is a restriction on total length.
 
 

Recent GIDBlog2nd Week of IA Training by crystalattice

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
A couple questions about Fl_Tabs WW. FLTK Forum 3 07-Oct-2004 07:04
Couple of questions Memory and CD RW schuumi Computer Hardware Forum 3 15-Sep-2004 15:32
Hello from cali, questions about web design jonnydangerous New Member Introductions 3 20-Aug-2004 13:59
Multi-Lingual Webpages & A Couple General Questions. dwaunthomas Web Design Forum 5 15-May-2004 11:07
Simple questions? Netizen Dave Apache Web Server Forum 3 17-Mar-2004 04:45

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 02:18.


vBulletin, Copyright © 2000 - 2008, Jelsoft Enterprises Ltd.