NameSilo

If $name = This, don't include in array

SpaceshipSpaceship
Watch

Tree

Established Member
Impact
9
I can't figure out how to get this piece of code working right.

PHP:
foreach ($func_country_array as $key => $value)
{
if (in_array("BLANK",$key)) 
{
next($func_country_array);
}
$disp_value = (strtoupper($key));
echo "<option value='".$key."'";
if ($_POST['location']) 
{						
if (in_array($key,$_POST['location'])) 
{
echo "selected='selected'";
}
}
echo ">".$disp_value."</option>
";
}

What it should be doing is if the foreach comes across "BLANK" to not include it. How do I get it to do that? Next doesn't seem to work.
 
0
•••
The views expressed on this page by users and staff are their own, not those of NamePros.
AfternicAfternic
Instead of using your next statement, why not just use an else in there like this:

Code:
foreach ($func_country_array as $key => $value)
{
if (in_array("BLANK",$key))
{
}else{
$disp_value = (strtoupper($key));
echo "<option value='".$key."'";
if ($_POST['location'])
{                        
if (in_array($key,$_POST['location']))
{
echo "selected='selected'";
}
}
echo ">".$disp_value."</option>
";
}
That way, if "BLANK" is in the array, it wont add it to your new array, it will simply do nothing.

OR a quicker one:
Code:
foreach($func_country_array as $key => $value){
  if(!in_array("BLANK",$key)){
  $disp_value = (strtoupper($key));
  echo "<option value='".$key."'";
    if($_POST['location']){                        
      if(in_array($key,$_POST['location'])){
      echo "selected='selected'";
      }
    }
  echo ">".$disp_value."</option>";
  }
}
This one will only do something if the array is NOT "BLANK".

Hope it works :red: .Let me know how it goes...

Regards, Rhett.
 
Last edited:
0
•••
Hmm, try this:
PHP:
foreach($func_country_array as $key => $value)
{
  if(in_array("BLANK",$key))
  {
    continue;
  }
  $disp_value = (strtoupper($key));
  echo "<option value='".$key."'";
  if($_POST['location'])
  {
    if(in_array($key,$_POST['location']))
    {
      echo "selected='selected'";
    }
  }
  echo ">".$disp_value."</option>";
}
 
0
•••
Alright, I'll try both of them and see. Thanks Billy and 2v!

<edit>
None of them worked. :(

Maybe it has something to do with the fact that BLANK is the key?
</edit>
 
Last edited:
0
•••
Tree said:
Alright, I'll try both of them and see. Thanks Billy and 2v!

<edit>
None of them worked. :(

Maybe it has something to do with the fact that BLANK is the key?
</edit>
Wait a tick, when you say "BLANK" do you mean that the array actually contains the word "BLANK" or just nothing, like this: ""?

Also, are you getting an error? Or is it just adding the blank which you dont want it to...?
 
Last edited:
0
•••
"BLANK" is the name of a key. It separates the common countries from the uncommon ones in another script. Its value is "_________________________________________"

And it's adding BLANK, which I don't want. Here's the page I'm working on:

http://www.vestieo.com/manage

Username: foo
Password: foo

Specifically, I'm working on the Location part.
 
0
•••
I dont quite know what you mean...
Do you mean that one of the VALUES in the array is "BLANK" or "___________" or something else?...

Sorry lol Im sure you know what your doing... If your talking about the VALUE of part of an array, then you can try this... seemed to work ok for me...
EDIT: Wait a minute lol
 
Last edited:
0
•••
I'd test it, but my FTP just went down :(

Sorry, here's a snippet of the array that I have.

PHP:
$func_country_array = array('ALL'=>'------ ALL COUNTRIES ------',
'GB'=>'UNITED KINGDOM',
'US'=>'UNITED STATES',
'BLANK'=>'_________________________________________',
'AF'=>'AFGHANISTAN',
'AL'=>'ALBANIA',

Here's what I currently have to call them.

PHP:
foreach($func_country_array as $key => $value)
				{
					if(in_array("BLANK",$key))
					{
						continue;
					}
					$disp_value = (strtoupper($key));
					echo "<option value='".$key."'";
					if($_POST['location'])
					{
						if(in_array($key,$_POST['location']))
						{
							echo "selected='selected'";
						}
					}
					echo ">".$disp_value."</option>";
				}

I just want not not display the BLANK.

Thanks everyone for their help thus far.
 
0
•••
Ohhh I see lol, ok, give me a couple minutes, I was confused as to whether or not you meant the name of the particular vaule in the array, or just the value :). Ok, be done in a minute or two (hopefully :P)
 
0
•••
Thanks Billy! :)
 
0
•••
PHP:
<?php

 $func_country_array = array('ALL'=>'------ ALL COUNTRIES ------',
'GB'=>'UNITED KINGDOM',
'US'=>'UNITED STATES',
'BLANK'=>'_________________________________________',
'AF'=>'AFGHANISTAN',
'AL'=>'ALBANIA');

foreach($func_country_array as $key => $value)
{
  if($key == "BLANK")
  {
    continue;
  }
  $disp_value = (strtoupper($key));
  echo "<option value='".$key."'";
  if($_POST['location'])
  {
    if(in_array($key,$_POST['location']))
    {
      echo "selected='selected'";
    }
  }
  echo ">".$disp_value."</option>";
}
?>
Output:
Code:
<option value='ALL'>ALL</option><option value='GB'>GB</option><option value='US'>US</option><option value='AF'>AF</option><option value='AL'>AL</option>
 
0
•••
Fixed:
Use this code to call them:
PHP:
foreach($func_country_array as $key => $value){
  if(strtolower($key)!="blank"){
  $disp_value = (strtoupper($key));
  echo "<option value='".$key."'";
    if($_POST['location']){
      if(in_array($key,$_POST['location'])){
      echo "selected='selected'";
      }
    }
  echo ">".$disp_value."</option>";
  }
}

[edit]Dang 2nd ver beat me to it! lol

All we did was change the "in_array" function becaues the "in_array" function only checks for values in the array, NOT the NAME of a value in the array...[/edit]
 
0
•••
It works! Thank you both so much! Rep given. :)
 
0
•••
No problem tree, let us know if youve got any more probs. And thanks for the rep :)
 
0
•••
Dynadot — .com TransferDynadot — .com Transfer
Appraise.net

We're social

Escrow.com
Spaceship
Rexus Domain
CryptoExchange.com
Domain Recover
CatchDoms
DomDB
NameFit
  • The sidebar remains visible by scrolling at a speed relative to the page’s height.
Back